Discussion:
Keyword out in C#
(too old to reply)
Patrick Chung
2015-11-20 11:31:21 UTC
Permalink
Parameter passed with keyword out in C# needs not to be initialized before it passed. It is applicable in defining several parameters and in checking if entered data is number, for example.

Read more:

http://www.cirvirlab.com/index.php/c-sharp-code-examples/keyword-out-and-code-examples-in-c.html
bradbury9
2015-11-20 13:13:17 UTC
Permalink
Post by Patrick Chung
Parameter passed with keyword out in C# needs not to be initialized before it passed. It is applicable in defining several parameters and in checking if entered data is number, for example.
http://www.cirvirlab.com/index.php/c-sharp-code-examples/keyword-out-and-code-examples-in-c.html
I personally think that using several out parameters in a function is usually a sympthom of lack of a class/struct. That example I would rewrite it as.

internal struct Parameters
{
internal string url;
internal string user;
internal string password;
}

...

internal bool GetInitParams(out Parameters initParams)
{
if(!isInitialized) return false;
//assign values to struct / class.
return true;
}


BTW, the microsoft c# reference is more complete, because it tells you what you can and cannot do with out keywords.

https://msdn.microsoft.com/en-us/library/t3c3bfhx.aspx
Arne Vajhøj
2015-11-28 21:42:12 UTC
Permalink
Post by bradbury9
Post by Patrick Chung
Parameter passed with keyword out in C# needs not to be initialized
before it passed. It is applicable in defining several parameters
and in checking if entered data is number, for example.
I personally think that using several out parameters in a function is
usually a sympthom of lack of a class/struct.
Either struct or split method in multiple methods.

Arne

Continue reading on narkive:
Loading...