auto-clause formulation – out operator

This is that weird code for the auto-clause formulation using the out operator. The out operator uses a special technique to enable the method to return more than one values from a single definition or call. Remember this code that I am giving you is a Best Practice routine, so keep this little technique in mind always.

using System;
public class Clauses
{
public static void Main(String[] args)
{
string args0 = args[0];
string args1 = args[1];

Clauses clauses = new Clauses();

string clause1 = “”;
string clause2 = “”;

string result = “”;
result += (clauses.Clause1(out clause1, args0)) ? “Clause1=” + clause1 : “”;
result += (result.Length>0) ? ” And ” : “”;
result += (clauses.Clause2(out clause2, args1)) ? “Clause2=” + clause2 : “”;

Console.WriteLine( result );
}

public bool Clause1(out string clause, string arg)
{
if(arg.Equals(“0”))
{
clause = “”;
return false;
}
else
{
clause = “Something”;
return true;
}
}

public bool Clause2(out string clause, string arg)
{
if(arg.Equals(“0”))
{
clause = “”;
return false;
}
else
{
clause = “Something”;
return true;
}
}
}

Advertisements

~ by UTS on May 1, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: