What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Quick "translation": VB to C#

Quick "translation": VB to C#
Author: Message:
Chancer
Senior Member
****

Avatar

Posts: 648
Reputation: 7
35 / Male / Flag
Joined: May 2005
Status: Away
O.P. Quick "translation": VB to C#
I have this piece of code:
Visual Basic 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.

This post was edited on 07-21-2011 at 04:24 AM by Chancer.
07-21-2011 04:10 AM
Profile E-Mail PM Find Quote Report
Alexandre.Lefebvre
Junior Member
**

Avatar

Posts: 61
– / Male / Flag
Joined: Nov 2010
RE: Quick "translation": VB to C#
When declaring an array in C# it is length of the array.
Code is beautiful.
07-21-2011 01:13 PM
Profile PM Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: Quick "translation": VB to C#
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)
07-21-2011 02:03 PM
Profile PM Web Find Quote Report
Chancer
Senior Member
****

Avatar

Posts: 648
Reputation: 7
35 / Male / Flag
Joined: May 2005
Status: Away
O.P. RE: Quick "translation": VB to C#
So in VB I don't need to state the length?
07-21-2011 02:55 PM
Profile E-Mail PM Find Quote Report
Alexandre.Lefebvre
Junior Member
**

Avatar

Posts: 61
– / Male / Flag
Joined: Nov 2010
RE: Quick "translation": VB to C#
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>();
Code is beautiful.
07-21-2011 03:01 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On