Grasshopper

algorithmic modeling for Rhino

it is very easy to see,i think the result should be 1.2,but the output show error!

who can tell me how to do it,thank you very much!!!

Views: 510

Replies to This Discussion

"Not all code paths return a value" means that under certain conditions your function does not return a value at all. Basically, when inp <= 0.5 then your function does not return a value, you need to fix this by adding another return statement.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you,david

Hi Andrea,

in C# you must make sure that all function code paths return a value, and you need to do this in an explicit way. In the case above,

return 1.2; is only executed if inp is larger than 0.5.

You need to work out what happens in all other case, for example if inp is strictly less than 0.5, and also what is returned if it is exactly 0.5. In particular, C# checks for example that there is always a return value by seeing if there is an else with return, or there is a final return at the end of the method.

For example, something like this will work:

public double re(double inp)
{
  if (inp > 0.5) { return 1.2; }
  else if (inp < 0.5) { return 2.0; }
  else { return 0.0; }
}

You can also skip the { } after if() and else, if you only have one statement.

I'd suggest to read a book about C# if you have a little time. Everything will become a lot clearer.
For example, there is the Programmers' Heaven C# book you can read for free.

I hope it helps,

- Giulio
______________
giulio@mcneel.com

This is the file.

Attachments:

thank you,Giulio,i am reading the book you have recommended,Grazie!

I did read a book by Jesse Liberty on C# and that was useful for me back then.

- Giulio
______________
giulio@mcneel.com

i have downloaded Jesse Liberty's C# book a few minutes ago,:)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service