By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

Convert VB to C# (Redim array question)

P: n/a
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
Oct 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Oct 3 '06 #2

P: n/a
Thanks Marc!

"Marc Gravell" wrote:
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
Oct 3 '06 #3

P: n/a
(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
"Jason Chan" wrote:
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

Oct 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.