Convert Delphi to C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kostya Ergin

    #1

    Convert Delphi to C#

    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# ?


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Convert Delphi to 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 [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Kostya Ergin" <kostya@erginso ft.com> wrote in message
    news:OAZOukDbFH A.740@tk2msftng p13.phx.gbl...[color=blue]
    > 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# ?
    >
    >[/color]


    Comment

    • Carlos J. Quintero [.NET MVP]

      #3
      Re: Convert Delphi to C#

      string test(string param)
      {
      return param; // or whatever result
      }

      C# Programmer's Reference:

      http://msdn.microsoft.com/library/en...asp?frame=true


      --

      Best regards,

      Carlos J. Quintero

      MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
      You can code, design and document much faster.
      Free resources for add-in developers:
      MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.


      "Kostya Ergin" <kostya@erginso ft.com> escribió en el mensaje
      news:OAZOukDbFH A.740@tk2msftng p13.phx.gbl...[color=blue]
      > 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# ?
      >
      >[/color]


      Comment

      • Kostya Ergin

        #4
        Re: Convert Delphi to C#

        Yes, this that, that works, thanks!

        "Carlos J. Quintero [.NET MVP]" <carlosq@NOSPAM sogecable.com> wrote in
        message news:OO5lVpDbFH A.3488@tk2msftn gp13.phx.gbl...[color=blue]
        > string test(string param)
        > {
        > return param; // or whatever result
        > }
        >
        > C# Programmer's Reference:
        >
        >[/color]
        http://msdn.microsoft.com/library/en...tutorials.asp?
        frame=true[color=blue]
        >
        >
        > --
        >
        > Best regards,
        >
        > Carlos J. Quintero
        >
        > MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
        > You can code, design and document much faster.
        > Free resources for add-in developers:
        > http://www.mztools.com
        >
        > "Kostya Ergin" <kostya@erginso ft.com> escribió en el mensaje
        > news:OAZOukDbFH A.740@tk2msftng p13.phx.gbl...[color=green]
        > > 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# ?
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Kostya Ergin

          #5
          Re: Convert Delphi to C#

          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
          message news:uJOK5mDbFH A.3932@TK2MSFTN GP12.phx.gbl...[color=blue]
          > 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[/color]
          something.[color=blue]
          > Also, I don't know what the default is for passing parameters in Delphi[/color]
          (is[color=blue]
          > param passed by value, or by reference?), but the C# code is passing the
          > string reference by value.
          >[/color]

          value or reference, in any way.
          [color=blue]
          > Hope this helps.[/color]

          thanks
          [color=blue]
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >
          > "Kostya Ergin" <kostya@erginso ft.com> wrote in message
          > news:OAZOukDbFH A.740@tk2msftng p13.phx.gbl...[color=green]
          > > 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# ?
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: Convert Delphi to C#

            Kostya Ergin <kostya@erginso ft.com> wrote:[color=blue][color=green]
            > > 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.[/color]
            >
            > value or reference, in any way.[/color]

            I'm not entirely sure what you were trying to say - Nicholas was
            exactly correct, the string reference is passed by value.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • C# Learner

              #7
              Re: Convert Delphi to C#

              Kostya Ergin <kostya@erginso ft.com> wrote:
              [color=blue]
              > 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# ?[/color]

              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 InsertClassName Here.test(param : string): string;
              begin
              end;

              Comment

              Working...