VB to C# Code Translator

402 views Asked by At

I am convering VB code to c#:

Private Function SoundsLike(ByVal pWord As String, 
             Optional ByRef pAccuracy As Byte = 6) As String.

But I got different type of parameters. Let me know how can I write in C#.

3

There are 3 answers

5
abatishchev On

The code like the following:

private string SoundsLike(string pWord, byte pAccuracy = 6);

requires C# 4.0 because contains optional parameters. For earlier version the same can be achieved via overload.

2
Nikhil Agrawal On

Use

private string SoundsLike(string pWord, byte pAccuracy = 6)

OR just

 private string SoundsLike(string pWord, out byte pAccuracy)

Private is optional. If no modifier given, default is Private

void abc(){}

is same as

private void abc() {}

Same with variables.

0
Jason Jong On

VB.Net

Private Function SoundsLike(ByVal pWord As String, Optional ByRef pAccuracy As Byte = 6) As String

C#

private string SoundsLike(string pWord, byte pAccuracy = 6)
{
}

private string SoundsLike(string pWord, out byte pAccuracy)
{
}

Note that out and ref cant have a default values

FYI : "The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed." Reference: http://geekswithblogs.net/ftom/archive/2008/09/10/c-and-the-difference-between-out-and-ref.aspx