Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Dim intListPrice As Integer = 0
Dim rowList As New Collection
Dim intCoutner As Integer = 1

intListPrice = intListPrice + DirectCast(rowList(intcolCounter), Object())(10)


What is meaning of above code and what is the equivalent code in c# for above code? 
Posted
Comments
Herman<T>.Instance 14-Aug-15 9:56am    
The meaning? The values are cast to object from the type they were.

in c#:

int intListPrice = 0;
Collection rowList = new Collection();
int intCoutner = 1;

intListPrice += (object[])rowList(intcolCounter)(10);

From VB to C# can be done via converters found via google....

1 solution

To cast a variable in C#, you just prefix teh value to cast with teh type you want in brackets:
C#
MyType mt = (MyType) value;
So in your example it would be:
C#
intListPrice += (int) rowList[10];
 
Share this answer
 
Comments
Richard Deeming 14-Aug-15 10:33am    
The direct equivalent of the VB.NET code would be closer to:
Convert.ToInt32(((object[])rowList)[10])

But without knowing what the non-generic Collection type looks like, there's no way to know if that's correct. :)
Kailas_ 17-Aug-15 0:41am    
Thanks Richard Deeming it works..!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900