public Point3d l(Line x, out Point3d st, out Point3d en)
{
st = x.PointAt(0);
en = x.PointAt(1);
}
It display Error(CS0161).
I’m studying C# now. So I need your help! Thank you!
public Point3d l(Line x, out Point3d st, out Point3d en)
{
st = x.PointAt(0);
en = x.PointAt(1);
}
It display Error(CS0161).
I’m studying C# now. So I need your help! Thank you!
You have declared that the function returns a Point3d
but you don’t return anything.
You should probably do this:
public void l(Line x, out Point3d st, out Point3d en)
{
st = x.PointAt(0);
en = x.PointAt(1);
}
Thank you!
But I face another problem.
private void RunScript(Line x, ref object A)
{
Point3d st;
Point3d en;
A = testout(x, out st, out en);
}
It display Error CS0029.
How can I convert void to object?
You need to study basic C# programming first. Your questions are difficult to answer without more context, I’m afraid.
Thank you! I’m studying basic now. But when I try to write something, I found so many things that I can’t find in book.
If you want to your function to assign something to a value it cannot return void.
If your function has anything ither than a void reupturn, it must in fact return something.
The easiest fix in this case is to remive the “A =” bit entirely.
It would also help if you explain what it is you’re trying to do.
Thank you!
I’m studying C# basic. I’m trying to understand out property. So I try to write some code to have a try. I want to use out property to return value more than just one.
Yup, that’s what out
is for. It’s really just syntactic sugar which helps to make sure that you always assign a specific argument and that the caller knows that a specific argument is meant to be assigned by the function, not them.
I do myself use out
, though I always try to avoid it if there’s an good alternative. I almost never use ref
arguments.
If, after understanding out parameters, you don’t like them, you can also use a tuple to return multiple values from a function. I think in most cases I prefer them, the only problem is that it’s not self documenting (you’ll have to add some comment instead of relying on variable names to remember what’s happening).
private void RunScript(Line x, object y, ref object A)
{
var ends = Test(x);
A = ends.Item1;
}
// <Custom additional code>
public Tuple<Point3d,Point3d> Test(Line x)
{
return Tuple.Create(x.PointAt(0), x.PointAt(1));
}