Understanding this bit of C# code

Posted on 2007-10-15
Last Modified: 2010-04-15
The line i'm interested in understanding is just before the for loop:
     sampleClass.Students = new List<StudentData>();

The 2 C# to VB translators I use both choke on that line. It's specific to webservices? What's it look like in VB?

public ClassData GetRoster(int numberOfStudents)
     ClassData sampleClass = new ClassData();
     sampleClass.ClassName = "Science";
     sampleClass.TeacherName = "Smith";
     sampleClass.TeacherID = 10;
     sampleClass.Students = new List<StudentData>();
           for (int i = 0; i < numberOfStudents; i++)
                 StudentData studentOne = new StudentData();
                 studentOne.StudentID = i + 1;
                 student.StudentName = (i%2 == 0 ? "Denis" : "Alexey");
     return sampleClass;
Question by:juststeve
    1 Comment
    LVL 16

    Accepted Solution

    It's not specific to Web services it's just creating an instance of the List Generic Class

    Example from MSDN:
            Dim dinosaurs As New List(Of String)
            List<string> dinosaurs = new List<string>();

    Your Example in VB.NET would be: -

    sampleClass.Students = new List(Of StudentData);

    For more info see: -

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now