Saturday, December 18, 2010

Unity3d + C#: Return-able functions in C#

I'm still new to the C# environment, and is working on my first application coded entirely using C#...

So when I was using Java, functions can always be return by simply writing the "return" phrase, followed by the value you want to return:
function ReturnAValue(a,b,c) {
    return a+b+c;

But after coding for a while in C#, I realize that I just can't simply put the "return" phrase in a void function (in C# they use "void", instead of "function", really confusing for beginners)... So anyway, I figure out a way to deal with it at the moment. Say you want to return a "float" value in a new function, here's what you do: instead of writing "void", you write "float" follow by the name of the function:
float ReturnFloatValue(float a, float b, float c) {
    return a+b+c;

Haven't try other variable types yet, but I guess it's pretty much the same... Will practice more on XNA as soon as I'm done with my current project~

No comments: