Parameter out and reference


   


using System;  


class ReferenceAndOutputParamtersTest
{
   static void Main( string[] args )
   {

      int y = 5;
      int z; 

      Console.WriteLine( "Original value of y: {0}", y );
      Console.WriteLine( "Original value of z: uninitialized
" );

      SquareRef( ref y ); // must use keyword ref
      SquareOut( out z ); // must use keyword out

      Console.WriteLine( "Value of y after SquareRef: {0}", y );
      Console.WriteLine( "Value of z after SquareOut: {0}
", z );

      Square( y );
      Square( z );

      Console.WriteLine( "Value of y after Square: {0}", y );
      Console.WriteLine( "Value of z after Square: {0}", z );

   } 
   static void SquareRef( ref int x )
   {
      x = x * x;
   }

   static void SquareOut( out int x )
   {
      x = 6;
      x = x * x;
   } 

   static void Square( int x )
   {
      x = x * x;
   } 

}
           
          


Iff operator in C#

   
 

//Octavalent Extension Methods
//http://sdfasdf.codeplex.com/
//Library of extension methods for .Net create by Octavalent (www.octavalent.nl)


namespace System.OctavalentExtensions
{
    public static class BooleanExtensions
    {
        public static object Iff(this bool value, object valueIfTrue, object valueIfFalse)
        {
            if (value)
                return valueIfTrue;

            return valueIfFalse;
        }
    }
}