Is there an easy way to do this? Or....does it have to be done one step at a time?
Thanks!
Printable View
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 translationQuote:
Originally Posted by birthjay
Can you show the C class maybe the function you're trying to translate is already exist in the FW.
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);
}
http://www.vbforums.com/showthread.p...ghlight=unsafe
Maybe this discussion can help .Using "unsafe" keyword you can use declare pointers
E.g : http://msdn.microsoft.com/library/de...clrfUnsafe.asp
http://www.csharpfriends.com/Article...?articleID=351
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:)Quote:
Originally Posted by birthjay
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
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:(Quote:
Originally Posted by birthjay
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)
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 headerCode: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;
}
Ok..thank you all for the good info.
hypotQuote:
Originally Posted by birthjay
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);