OOPS - Interface, Abstract, Delegate well explained in code







using System;
using System.CodeDom.Compiler ;

namespace csharpoops
{
 

                  abstract class test1
                {
                                  public abstract int Fun(int a,int b);   

                                  public int Checking(int d,int e)


                                  { 
                                                 d=3346;

                                               e=123;
                                               return d-e; 

                                  }
                  }

                 //Interface Example

                   public interface Icalc
                { 

                                  int fn_add(int x, int y );


                }

                 //Structure Example

                    struct employee


                {

 
                                 public string name;
                                 public int age;
                                 public long salary; 

                }

 
                 //Enumerator Example


                 public enum state


                {

                               off = 1,

                                on   = 2

 

                }

 
                 // Delegate Example

                 public delegate void simpledelegate();


                 public delegate int advdelegate();


                 delegate void CheckDelegate();

 
                                 class Class1:test1,Icalc 

                               

                                                //Abstract Class  

                                                public override int Fun(int x,int y) 

                                                {
                                                                return x + y;

                                                }

                                                 // Interface implementation


                                                public int fn_add(int x, int y)
 

                                                {

                                                                return x + y; 

                                                }

                                                 public long fn_add(long y , long z) 

                                                { 

                                                                return y + z;

                                                }

                                                 public double fn_add(double x,double y,double z) 
                                                {

                                                                return x + y + z; 

                                                }

                                                 public string fn_add(string x,string y,string z)  

                                                { 

                                                                return x + y + z;

                                                }

                                                 public static void fn_welcome() 

                                                {

                                                                Console.WriteLine("Welcome to Delegates"); 

                                                }

                                                 public void fn_afterdelg() 

                                                {

                                                                Console.WriteLine("Welcome to after delegates"); 

                                                }

                                                 // Declaring string type property 'name' 

                                                string m_name; 

                                                string Value=""; 

                                                public string name 

                                                {

                                                                get 

                                                                {
                                                                                return m_name;

                                                                } 

                                                                set 

                                                                {

                                                                                m_name = Value; 

                                                                 } 

                                                }

                                                 static void Main(string[] args)


                                                {

                                                                int i1; 

                                                                long l1=3356544876; 

                                                                Console.WriteLine("Logn value" + l1); 

                                                                i1=(int)l1; 

                                                                Console.WriteLine("Integer value" + i1);  

                                                                employee emp; 

                                                                emp.name ="ravi";

                                                                emp.age =25; 

                                                                emp.salary = 10000;                          
                                                                Console.WriteLine("*****************structure implementation*******************");

 

                                                                Console.WriteLine(emp.name); 

                                                                Console.WriteLine(emp.age); 

                                                                Console.WriteLine(emp.salary);                                              

                                                                Console.WriteLine("*****************Enumerator implementation*******************"); 

                                                                state x; 

                                                                x = state.off;

                                                                 switch(x) 

                                                                { 

                                                                                case state.on: 

                                                                                Console.WriteLine("iam here at on state"); 

                                                                                                break;

 

                                                                                case state.off: 

                                                                                                Console.WriteLine("iam here at off state");
                                                                                                break;

                                                                }

 

                                                                int y ;

 

                                                                y = 0;

 

 

 

                                                                switch(y)

 

                                                                {

 

                                                                                case 1:

 

                                                                                                Console.WriteLine(state.off);

 

                                                                                                break;

 

                                                                                case 2:

 

                                                                                                Console.WriteLine(state.on);

 

                                                                                                break;

 


                                                                }

 

                                                                Console.WriteLine("******************** Interface implementation ***********************");

 
                                                                Class1 obj =  new Class1();

                                                                int  resint;

 

                                                                resint = obj.fn_add(3,4);

 

                                                                Console.WriteLine("the value of function add int   " + resint);

 

                                               

 

                                                                long reslong;

 

                                                                reslong = obj.fn_add(2,1);

 

                                                                Console.WriteLine("the value of function add long   " + reslong);

 

                                                

 

                                                                double resdbl;

 

                                                                resdbl = obj.fn_add(2,3,4);

 

                                                                Console.WriteLine("the value of function add double   " + resdbl);

 

 

 

                                                                string resstring;

 

                                                                resstring = obj.fn_add("ravi","krishnan","rajasekaran");

 

                                                                Console.WriteLine("the value of function add string   " + resstring);

 

                                   

 

                                                                Console.WriteLine("*********************** Delegate Implementation ***********************");

 

           

 

                                                                simpledelegate delobj = new simpledelegate(fn_welcome);

 

                                                                delobj();

 

 

 

                                                                simpledelegate delaftobj = new simpledelegate(obj.fn_afterdelg);

 

                                                                delaftobj();

 

 

 

                                                                Console.WriteLine("*********Abstract Class***********");

 

                                                                int result;

 

                                                                result = obj.Fun(4,69);

 

                                                                Console.WriteLine("The abstract class result is" + result);

 

                                                                Console.ReadLine();

 

                     

Comments

Popular posts from this blog

Run Powershell script on Remote Computer/Server

Power BI Refresh Issue: unable to convert the value '' from the source data type 'VT_BSTR' to the expected data type 'VT_I8.

SPDActivities - DP.SharePoint.Workflow - Workflow failed to run