Click to See Complete Forum and Search --> : Convert C class to C# ??
birthjay
Feb 18th, 2005, 07:43 AM
Is there an easy way to do this? Or....does it have to be done one step at a time?
Thanks!
MrPolite
Feb 18th, 2005, 02:04 PM
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
Pirate
Feb 18th, 2005, 07:14 PM
Can you show the C class maybe the function you're trying to translate is already exist in the FW.
birthjay
Feb 21st, 2005, 07:53 AM
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);
}
Pirate
Feb 21st, 2005, 01:48 PM
http://www.vbforums.com/showthread.php?t=260563&highlight=unsafe
Maybe this discussion can help .Using "unsafe" keyword you can use declare pointers
E.g : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfUnsafe.asp
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=351
birthjay
Feb 21st, 2005, 02:43 PM
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?
MrPolite
Feb 21st, 2005, 03:24 PM
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
birthjay
Feb 21st, 2005, 03:36 PM
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);
}
MrPolite
Feb 21st, 2005, 03:45 PM
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)
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
birthjay
Feb 21st, 2005, 03:47 PM
Ok..thank you all for the good info.
Pirate
Feb 21st, 2005, 07:23 PM
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 (file:///D:/Books/C%20-%20C%20+%20+/Books/WWW/ANSI%20STANDARD%20C%20FUNCTION%20DEFINITIONS/member~1.com/wanton~1/default.htm#math.h99)
PURPOSE
To return the square root of .x times x plus y times y.
atan2
double atan2 (double first, double second)
HEADER math.h (file:///D:/Books/C%20-%20C%20+%20+/Books/WWW/ANSI%20STANDARD%20C%20FUNCTION%20DEFINITIONS/member~1.com/wanton~1/default.htm#MATH)
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);
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.