Wednesday, March 12, 2008

Operator set in method's parameters.

Usually before method's calling we set all method's parameters by next way:

int value;

value = 4;
Console.WriteLine(String.Format("sqrt({0}) = {1}", value, Math.Sqrt(value)));
value = 9;
Console.WriteLine(String.Format("sqrt({0}) = {1}", value, Math.Sqrt(value)));

But C# allows set of method's parameters during method's calling by suggested way:

Console.WriteLine(String.Format("sqrt({0}) = {1}", value = 25, Math.Sqrt(value)));
Console.WriteLine(String.Format("sqrt({0}) = {1}", value = 16, Math.Sqrt(value)));

Console output:

consoleOutputSet

All sources can be download from google code project csharp-tips "google code" project

No comments: