A bit of help

ggerard

New member
Joined
Apr 27, 2009
Messages
2
Programming Experience
5-10
Greetings all,
I've been going through a project that was orignially done in C# and converting it to vb.net (the original coder quit the project so I'm taking over and I dont much care for C#). Anyway, I'm down to 3 errors and they are all basically the same, it has to do with the sortedlist object.

The original line of code was this:

(list = this.m_dDamagePoints)[time = parsedLine.TimeStamp] = list[time] = parsedLine.Damage;

where:

list and m_dDamagePoints is a Sortedlist(Of Datetime, Long)

My question is, what is that line of c# code actually doing, and as a bonus, what would be the vb.net equivalent?

I ran it through a c# to vb.net converter and it came up with:
list = Me.m_dDamagePoints.Item(time = parsedLine.TimeStamp) = (list.Item(time) + parsedLine.Damage)

which is not valid of course. any ideas?
 
That is some of the worst C# code I've ever seen. Not only is it confusing but it's also redundant. For what that code actually does, it should simply be written:
VB.NET:
this.m_dDamagePoints[parsedLine.TimeStamp] = parsedLine.Damage;
I'm guessing that you can work out the VB equivalent of that for yourself but, just in case:
VB.NET:
Me.m_dDamagePoints(parsedLine.TimeStamp) = parsedLine.Damage
The key to understand why and how that ridiculous line of code worked is the fact that in C# an assignment returns a value, specifically the value that was assigned, while in VB they don't. For instance, this part:
VB.NET:
(list = this.m_dDamagePoints)[B][U][time = parsedLine.TimeStamp][/U][/B] = list[time] = parsedLine.Damage;
assigns the value of parsedLine.TimeStamp to time and then returns that value. That return value is then used as a key into the list that's returned by the previous assignment.
 
Thanks

That makes so much more sense now...
yeah, I can see what you mean... very .. umm.. 'creative' way to do a simple assignment.
Thanks again for the help.


P.S. the former worker is now driving trucks for a living... still feel safe on the highway? :)
 
Back
Top