Convert VB to C# (Redim array question)

G

Guest

I am converting a sample VB program to C#, and I stopped at lines of code I
dont know how to write in C#, that is the Redim statement.

In the VB:

Private Function DoSomething(ByRef lBegin() as Long) As Boolean
'some codes
ReDim lBegin(0) '
lBegin(0) = 0 ' how do i write this 2 lines in C#?

' some codes

Return True
End Function

Thanks in advance
Jason
 
M

Marc Gravell

Just reasssign:

private static bool DoSomething(ref long[] lBegin) {
lBegin = new long[] { (long) 0 };
return true;
}

Could also use a separate assignement and set statement, although since 0 is
the default even this is overkill:
lBegin = new long[1];
lBegin[0] = 0; // unnecessary

However, I'd make it a void (Sub) myself unless it can return values other
than true (and use exceptions to handle errors).

Marc
 
G

Guest

(via Instant C#)
private bool DoSomething(ref long[] lBegin)
{
//some codes
lBegin = new long[1];
lBegin[0] = 0; // how do i write this 2 lines in C#?

// some codes

return true;
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top