Reputation: 151
I'm a beginner in programming and i would like to know how can i translate the following code into C#
Dim arrayAlumnos(ds.Tables(0).Rows.Count - 1) As Registro
Upvotes: 0
Views: 175
Reputation: 31406
To preserve the array idea I'd probably write it like:
var arrayAlumnos = new Registro[ds.Tables[0].Rows.Count];
But you could say this too:
Registro[] arrayAlumnos = new Registro[ds.Tables[0].Rows.Count];
But ChaosPandion is right... a List is what you'd want to use most likely.
Upvotes: 3
Reputation: 8208
FYI, if you want to convert a lot of code from VB to C#, you can use the ILSpy disassebler. You can do this even if you don't have the original VB code. Do this:
Compile the VB code into a *.exe or a *.dll.
Open the *.exe or *.dll file in ILSpy.
In the language dropdown, select VB. (It's values are C#, VB, and MSIL).
Upvotes: 0
Reputation: 13765
you'll probably have a lot of one off questions like this going through your travels of conversion, might want to take a look at:
http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx
The basic idea behind the creation in C# is...
~ObjectType~ ~varName~ = new ~type~(~implement a type constructor here~);
anything in between ~~s you'll need to plug in the appropriate information. For your case it would likely be:
Registro[] arrayAlumnos = new Registro[ds.Tables[0].Rows.Count - 1];
Kind of hard since it's a different spoken language but based on your variable name i'm guessing it's an array, though as others pointed out it could easily be created as a list.
Upvotes: 0
Reputation: 78242
You should be using a list so I think this is the proper translation.
List<Registro> students = new List<Registro>();
Upvotes: 3