Creating Classes with No Objects via static methods - CSharp Custom Type

CSharp examples for Custom Type:static

Description

Creating Classes with No Objects via static methods

Demo Code

using System;/*from  w  w  w .java 2  s .c o  m*/
public class MyMath
{
   public static long Add( params int[] args )
   {
      int i = 0;
      long Answer = 0;
      for( i = 0; i < args.Length; i++)
      {
         Answer += args[i];
      }
      return Answer;
   }
   public static long Subtract( int arg1, int arg2 )
   {
      long Answer = 0;
      Answer = arg1 - arg2;
      return Answer;
   }
}
class MainClass
{
   public static void Main()
   {
      long Result = 0;
      Result = MyMath.Add( 1, 2, 3 );
      Console.WriteLine("Add result is {0}", Result);
      Result = MyMath.Subtract( 5, 2 );
      Console.WriteLine("Subtract result is {0}", Result);
   }
}

Result


Related Tutorials