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
ASKER CERTIFIED SOLUTION
kprestage

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 23 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 23 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004