Results 1 to 11 of 11

Thread: Convert C class to C# ??

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Convert C class to C# ??

    Is there an easy way to do this? Or....does it have to be done one step at a time?

    Thanks!

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Convert C class to C# ??

    Quote Originally Posted by birthjay
    Is there an easy way to do this? Or....does it have to be done one step at a time?

    Thanks!
    eh C has nothing to do with C#, they just have a similar syntax. hehe I think you have to go through painful step by step translation
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Can you show the C class maybe the function you're trying to translate is already exist in the FW.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Convert C class to C# ??

    Well...just as an example...How would this convert to C#:

    compute_solution (solu,posit,x,y)
    float *solu, *posit, *x, *y;
    {
    *solu= hypot(*x,*y);
    *posit =atan2(*y,*x);
    }

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Convert C class to C# ??

    Thanks. I have seen the "Unsafe" thing, but I really want to go straight away to C#. The "Unsafe" thing seems to be a work-a-round. Am I wrong on that?

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Convert C class to C# ??

    Quote Originally Posted by birthjay
    Thanks. I have seen the "Unsafe" thing, but I really want to go straight away to C#. The "Unsafe" thing seems to be a work-a-round. Am I wrong on that?
    umm for security reasons, you can only and only use pointers in C# using unsafe{}. No way around that either
    the point is, when you use unsafe then the .NET framework will only run your app on someone's comp if the security settings are not too tight. It's just to avoid system damage etc and all those viruses that rely on pointers
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Convert C class to C# ??

    Thanks...

    Well..say in the code below...can I just pass by "ref" and accomplish the same thing?

    compute_solution (solu,posit,x,y)
    float *solu, *posit, *x, *y;
    {
    *solu= hypot(*x,*y);
    *posit =atan2(*y,*x);
    }

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Convert C class to C# ??

    Quote Originally Posted by birthjay
    Thanks...

    Well..say in the code below...can I just pass by "ref" and accomplish the same thing?

    compute_solution (solu,posit,x,y)
    float *solu, *posit, *x, *y;
    {
    *solu= hypot(*x,*y);
    *posit =atan2(*y,*x);
    }
    aah sorry I dont even understand what that code does
    but if you want to pass things by reference here's how to do it in c# (and, no, for this one you wont need the unsafe block)
    Code:
    private void Form1_Load(object sender, System.EventArgs e)
    		{
    			int num=9;
    			testing (ref num);
    
    			MessageBox.Show (num.ToString());
    		}
    
    		private void testing (ref int num)
    		{
    			num*=9;
    		}
    so when you call the function and you are passing the parameter, you need to put the REF keyword before the parameters name. And same applies in the function header
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Convert C class to C# ??

    Ok..thank you all for the good info.

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Quote Originally Posted by birthjay
    Well...just as an example...How would this convert to C#:

    compute_solution (solu,posit,x,y)
    float *solu, *posit, *x, *y;
    {
    *solu= hypot(*x,*y);
    *posit =atan2(*y,*x);
    }
    hypot

    double hypot( double x, double y)

    HEADER math.h

    PURPOSE
    To return the square root of .x times x plus y times y.


    atan2

    double atan2 (double first, double second)

    HEADER math.h

    PURPOSE
    To calculate the value of the arc tangent of first divided by second, using the signs of both arguments to calculate its quadrant.


    These functions are available in .NET under Math class . So , there's no need to rewrite your code . Your code just store the return type into float variables which is also possible in C#.

    System.Math.Atan2 (y,x);

    System.Math.Sqrt(x);


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width