problem in converting a c++ bit of code to its c# counter part

This is a discussion on problem in converting a c++ bit of code to its c# counter part within the C# Programming forums, part of the General Programming Boards category; hello all , i was asked to convert a c++ sourcecode into its c# counter part , but i have ...

  1. #1
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493

    problem in converting a c++ bit of code to its c# counter part

    hello all ,
    i was asked to convert a c++ sourcecode into its c# counter part , but i have no idea how i should go about this particular snippet of code.
    i would be very thankful if anyone assists me in this problem .
    the c++ snippet of code is this :
    Code:
     typedef double (*FunctionCallback)(double sol[D]);
    FunctionCallback function = &sphere;
    and this is sphere function , already converted to c#
    Code:
    static double sphere(double[] sol)
    {
        int j;
        double top=0;
        for(j=0;j<sol.Length;j++)
        {
            top=top+sol[j]*sol[j];
        }
        return top;
    }
    Thankyou in advance.
    Last edited by Masterx; 01-01-2011 at 06:08 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,203
    Look into delegates:
    Code:
    delegate double FunctionCallback(double[] sol);
    FunctionCallback callBack = sphere;

  3. #3
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by Shakti View Post
    Look into delegates:
    Code:
    delegate double FunctionCallback(double[] sol);
    FunctionCallback callBack = sphere;
    thank you verymuch .i just found that out .
    is this also correct?
    FunctionCallback function = new FunctionCallback(sphere);[/CODE]
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple C code problem
    By neo28 in forum C Programming
    Replies: 24
    Last Post: 05-16-2009, 10:48 AM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  4. Quite a stuffed bit of code actually.
    By Joshua-NSW in forum C Programming
    Replies: 4
    Last Post: 11-02-2001, 01:41 AM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21