Convert Delphi to C#

  • Thread starter Thread starter Kostya Ergin
  • Start date Start date
K

Kostya Ergin

hi, i am very new in C#.

How to do this in C#:

This is function:
function test(param: string): string;
begin
end;

I can get result of "test" function:
result := test(param);


And how to do in C# ?
 
Kostya,

I've never used Delphi, but it looks like you would use:

string test(string param)
{
return null;
}

There is a "return null" in there because you need to return something.
Also, I don't know what the default is for passing parameters in Delphi (is
param passed by value, or by reference?), but the C# code is passing the
string reference by value.

Hope this helps.
 
Nicholas Paldino said:
Kostya,

I've never used Delphi, but it looks like you would use:

string test(string param)
{
return null;
}

There is a "return null" in there because you need to return something.
Also, I don't know what the default is for passing parameters in Delphi (is
param passed by value, or by reference?), but the C# code is passing the
string reference by value.

value or reference, in any way.
Hope this helps.
thanks



--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kostya Ergin said:
hi, i am very new in C#.

How to do this in C#:

This is function:
function test(param: string): string;
begin
end;

I can get result of "test" function:
result := test(param);


And how to do in C# ?
 
Kostya Ergin said:
value or reference, in any way.

I'm not entirely sure what you were trying to say - Nicholas was
exactly correct, the string reference is passed by value.
 
Kostya Ergin said:
This is function:
function test(param: string): string;
begin
end;

I can get result of "test" function:
result := test(param);

And how to do in C# ?

The closest you can get to a Delphi function in C# would be a non-void
static method:

static string test(string param) {
// this won't compile since this method is non-void and no value is
// returned, and that's not valid C#
}

FWIW, C# static methods are pretty much the same as Delphi class methods.
Therefore, the above is pretty much the same as:

class function InsertClassNameHere.test(param: string): string;
begin
end;
 

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

Back
Top