Shoutbox

Quick "translation": VB to C# - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Quick "translation": VB to C# (/showthread.php?tid=98010)

Quick "translation": VB to C# by Chancer on 07-21-2011 at 04:10 AM

I have this piece of code:

VB code:
Dim moniker As IMoniker() = New IMoniker(0) {}

Is this an array initlialized with length 0?
Is it right to "translate" it as:
C# code:
IMoniker[] moniker = new IMoniker[0];
?

I'm translating a program, and there's an error happening when using that moniker. It works fine with VB, but not with C#, and I guess the error is in the declaration.

Edit: I tried to change to:
C# code:
IMoniker[] moniker = new IMoniker[1];
I'm not sure about that 0 in the VB code. Is that the length or just an index? I'd appreciate a little info about that.
RE: Quick "translation": VB to C# by Alexandre.Lefebvre on 07-21-2011 at 01:13 PM

When declaring an array in C# it is length of the array.


RE: Quick "translation": VB to C# by Mnjul on 07-21-2011 at 02:03 PM

quote:
Originally posted by Chancer
Is this an array initlialized with length 0?
No, it's an array with index upper bound = 0. (lower bound = 0 if unspecified)
RE: Quick "translation": VB to C# by Chancer on 07-21-2011 at 02:55 PM

So in VB I don't need to state the length?


RE: Quick "translation": VB to C# by Alexandre.Lefebvre on 07-21-2011 at 03:01 PM

If you don't want to state the lenght at the declaration and deal with array resising I would suggest that you use a typed collection.

In C#
System.Collections.Generic.List<IMoniker> moniker = new System.Collections.Generic.List<IMoniker>();