troubleshooting Question

Convertion from VB to C#

Avatar of janjuama84
janjuama84 asked on
C#
23 Comments1 Solution461 ViewsLast Modified:
Can somebody please convert following code to C#?


''' <summary>
''' This page allows for classes to have seats deducted from it
''' </summary>
''' <remarks></remarks>
Partial Class _Default
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' if first load then setup classes
        If Not Page.IsPostBack Then

            InitialiseClasses()
            UpdateLabels()

        End If
    End Sub

    ''' <summary>
    ''' Initialises the Class Arrays based on parameters passed
    ''' </summary>
    ''' <param name="ClassSizes">The Size of the Classes</param>
    ''' <param name="AmountofClasses">The Amount of Classes to Create</param>
    ''' <remarks></remarks>
    Private Sub InitialiseClasses(Optional ByVal ClassSizes As Integer = 15, Optional ByVal AmountofClasses As Integer = 3)
        Dim TheClasses As New ArrayList()
        Dim i As Integer

        ' For the Amount of Classes Specified
        For i = 1 To AmountofClasses
            ' Add an integer of size ClassSizes to the ArrayList
            TheClasses.Add(ClassSizes)
        Next

        ' Add the Classes Arraylist to the Session
        Session("Classes") = TheClasses

        ' Create an Arraylist of the size of ClassSizes and bind it to the Radio List
        radSeatsAvailable.DataSource = PopulateArrayList(ClassSizes)
        radSeatsAvailable.DataBind()
    End Sub



    ''' <summary>
    ''' Creates and returns an array list of 1 to the specified size
    ''' </summary>
    ''' <param name="ArrayListLength">The Size of the ArrayList</param>
    ''' <returns>ArrayList of integers from 1 to ArrayListLength</returns>
    ''' <remarks></remarks>
    Private Function PopulateArrayList(ByVal ArrayListLength As Integer) As ArrayList
        Dim myarray As New ArrayList
        Dim i As Integer

        ' For the size of the arraylist
        For i = 1 To ArrayListLength
            ' Add an integer of the value i
            myarray.Add(i)
        Next

        Return myarray

    End Function



    ''' <summary>
    ''' Resets the radiolist when the dropdownlist with classes is changed
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub ddlClass_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlClass.SelectedIndexChanged

        ' ReBind the radiolist based on the amount of seats left in the class
        radSeatsAvailable.DataSource = PopulateArrayList(Session("classes").Item(ddlClass.SelectedIndex).ToString)
        radSeatsAvailable.DataBind()

        UpdateLabels()

    End Sub

    ''' <summary>
    ''' On Click update the amount of seats left in the class
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRegister.Click

        ' Deduct the amount of seats based on the radio button selected
        Session("classes").Item(ddlClass.SelectedIndex) = Session("classes").Item(ddlClass.SelectedIndex) - radSeatsAvailable.SelectedIndex - 1

        ' Bind the new amount of seats left
        radSeatsAvailable.DataSource = PopulateArrayList(Session("classes").Item(ddlClass.SelectedIndex).ToString)
        radSeatsAvailable.DataBind()

        UpdateLabels()

    End Sub


    ''' <summary>
    ''' Updates the labels for user feedback
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub UpdateLabels()
        lblClass1.Text = Session("classes").Item(0).ToString
        lblClass2.Text = Session("classes").Item(1).ToString
        lblClass3.Text = Session("classes").Item(2).ToString
    End Sub

End Class
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 23 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 23 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros