next


Local Global Varaible
Encapsulation


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{

    class Demo
    {
        int x;
        public void show()
        {
            int y = 10;
            x = 100;
            Console.WriteLine(x);
            Console.WriteLine(y);
        }

       public void disp()
        {
            int z = 20;
            x = 200;
            Console.WriteLine(x);
	    //Console.WriteLine(y); ERROR
            Console.WriteLine(z);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {

            Demo d = new Demo();
            d.show();
            d.disp();
            Console.Read();
        }
    }
}

Program for Max Number using NoReturn type with NoParameters
methods

/*Program for Max Number using NoReturn type with NoParameters*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Maxnum
    {
      public  void max()
        {
            int x = 12, y = 13;
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            Maxnum m = new Maxnum();
            m.max();
            Console.Read();
        }
    }
}

Program for Max Number using NoReturn type with Parameters

/*Program for Max Number using NoReturn type with Parameters*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Maxnum
    {
      public  void max(int x,int y)
        {
            
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Maxnum m = new Maxnum();
            m.max(12,15);
            Console.Read();
        }
    }
}

Program for Max Number using Return type with NoParameters

/*Program for Max Number using Return type with NoParameters*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Maxnum
    {
      public  int max()
        {
            int x = 12, y = 24;
            if (x > y)
            {
                return x;
            }
            else
            {
                return y;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Maxnum m = new Maxnum();
            Console.WriteLine( m.max());
            Console.Read();
        }
    }
}

Program for Max Number using Return type with Parameters

/*Program for Max Number using Return type with Parameters*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Maxnum
    {
      public  int max( int x,int y)
        {
            
            if (x > y)
            {
                return x;
            }
            else
            {
                return y;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Maxnum m = new Maxnum();
            Console.WriteLine( m.max(12,14));
            Console.Read();
        }
    }
}

Constructor Program
Data abstruction


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum()
        {
            x = 12;
            y = 24;
      
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
       
		}

    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum();
            Console.Read();
        }
    }
}

Program for Max Number using NoReturn type with NoParameters With NoParameters Constructor
Constructor


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum()
        {
            x = 12;
            y = 23;

        }

        public void max()
        {
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum();
            m.max();
            Console.Read();
        }
    }
}

Program for Max Number using NoReturn type with Parameters With NoParametarized Constructor


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum()
        {
            x = 12;
            y = 23;

        }

        public void max(int p,int q)
        {
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum();
            m.max(100,200);
            Console.Read();
        }
    }
}

Program for Max Number using Return type with NoParameters With NoParametarized Constructor

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum()
        {
            x = 12;
            y = 23;

        }

        public int  max()
        {
            
            if (x > y)
            {
                return x;
            }
            else
            {
                return y;
            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum();
            Console.WriteLine(m.max());
            Console.Read();
        }
    }
}

Program for Max Number using Return type with Parameters With NoParametarized Constructor


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum()
        {
            x = 12;
            y = 23;

        }

        public int  max(int p,int q)
        {
            
            if (x > y)
            {
                return x;
            }
            else
            {
                return y;
            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum();
            Console.WriteLine(m.max(100,200));
            Console.Read();
        }
    }
}

Program for Max Number using NoReturn type with NoParameters With Parametarized Constructor


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum(int a,int b)
        {
            x = 12;
            y = 23;

        }

        public void max()
        {
            
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum(1000,2000);
           m.max();
            Console.Read();
        }
    }
}

Program for Max Number using NoReturn type with Parameters With Parametarized Constructor
                      

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum(int a,int b)
        {
            x = 12;
            y = 23;

        }

        public void max(int p,int q)
        {
            
            if (x > y)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(y);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum(1000,2000);
           m.max(100,200);
            Console.Read();
        }
    }
}

Program for Max Number using Return type with NoParameters With Parametarized Constructor



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum(int a,int b)
        {
            x = 12;
            y = 23;

        }

        public int  max()
        {
            
            if (x > y)
            {
                return x;
            }
            else
            {
                return y;

            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum(1000,2000);
            Console.WriteLine(m.max());
            Console.Read();
        }
    }
}

Program for Max Number using Return type with Parameters With Parametarized Constructor

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class maxnum
    {
        int x, y;
        public maxnum(int a,int b)
        {
            x = 12;
            y = 23;

        }

        public int  max(int p,int q)
        {
            
            if (x > y)
            {
                return x;
            }
            else
            {
                return y;

            }
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            maxnum m=new maxnum(1000,2000);
            Console.WriteLine(m.max(100,200));
            Console.Read();
        }
    }
}

Static
Static


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StaticDemo
{
    static class Sample
    {
        public static string SampleStaticMember = "This is my static data member";
        public static void SampleStaticMethod()
        {
            Console.WriteLine("This is my static method.");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Sample.SampleStaticMember);
            Sample.SampleStaticMethod();
            Console.Read();
        }
    }
}


Partial Classes


SampleClassPart1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PartialClasses
{
    partial class SampleClass
    {
        public void FirstMethod()
        {
            Console.WriteLine("This is first method.");
        }
    }
}

SampleClassPart2.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PartialClasses
{
    partial class SampleClass
    {
        public void SecondMethod()
        {
            Console.WriteLine("This is second method.");
        }
    }
}

SampleClassPart3.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PartialClasses
{
    partial class SampleClass
    {
        public void ThirdMethod()
        {
            Console.WriteLine("This is third method.");
        }
    }
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PartialClasses
{
    class Program
    {
        static void Main(string[] args)
        {
            SampleClass sc = new SampleClass();
            sc.FirstMethod();
            sc.SecondMethod();
            sc.ThirdMethod();
            Console.Read();
        }
    }
}

Constructors and Destructors and Copy Constructors
                                
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComplexDemoOnConstructorsAndDestructors
{
    class Student
    {
        //private data members
        private int StudentID;
        private string StudentName;
        //default constructor
        public Student()
        {
            StudentID = 101;
            StudentName = "Ram";
        }
        //parameterized constructor
        public Student(int StudentID, string StudentName)
        {
            this.StudentID = StudentID;
            this.StudentName = StudentName;
        }
        //copy constructor
        public Student(Student s)
        {
            StudentID = s.StudentID;
            StudentName = s.StudentName;
        }
        //destructor
        ~Student()
        {
            Console.WriteLine("This is destructor...");
        }
        //public method
        public void Display()
        {
            Console.WriteLine(StudentID + ", " + StudentName);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //invoke default constructor
            Student s1 = new Student();
                        s1.Display();
            //invoke parameterized constructor
            Student s2 = new Student(102, "sateesh");
            s2.Display();
            //invoke copy constructor
            Student s3 = new Student(s1);
            s3.Display();
            Console.Read();
        }
    }
}

Struct
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StructuresDemo
{
    struct Employee
    {
        public int EmployeeID;
        public string EmployeeName;
    }
    class Program
    {
        static void Main(string[] args)
        {
            Employee e;
            e.EmployeeID = 101;
            e.EmployeeName = "Laxman";
            Console.WriteLine(e.EmployeeID);
            Console.WriteLine(e.EmployeeName);
            Console.Read();
        }
    }
}

Single Inheritance
Inheritance


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
    class Demo
    {
        public string name;
        public string loc;
        public string gen;
    }

    class Demo1 : Demo
    {
        int age;

        public Demo1()
        {

            Console.WriteLine("enter name");
            name = Console.ReadLine();
            Console.WriteLine("Enter loc");
            loc = Console.ReadLine();
            Console.WriteLine("Enter gen");
            gen = Console.ReadLine();
            Console.WriteLine("Enter age");
            age = Convert.ToInt32(Console.ReadLine());
        }

        public void showDetails()
        {
            Console.WriteLine("your name is" + name);
            Console.WriteLine("your loc is" + loc);
            Console.WriteLine("your gen is" + gen);
            Console.WriteLine("your age is" + age);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Demo1 d = new Demo1();
            d.showDetails();
            Console.Read();
        }
    }
}

MultiLevel Inheritance

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
    class Demo
    {
        public string name;
        public string loc;
        
    }

    class A : Demo
    {
        public int age;
    }

    class B : A
    {
        public string gen;
    }


    class Demo1 :B
    {
        

        public Demo1()
        {

            Console.WriteLine("enter name");
            name = Console.ReadLine();
            Console.WriteLine("Enter loc");
            loc = Console.ReadLine();
            Console.WriteLine("Enter gen");
            gen = Console.ReadLine();
            Console.WriteLine("Enter age");
            age = Convert.ToInt32(Console.ReadLine());
        }

        public void showDetails()
        {
            Console.WriteLine("your name is" + name);
            Console.WriteLine("your loc is" + loc);
            Console.WriteLine("your gen is" + gen);
            Console.WriteLine("your age is" + age);
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            Demo1 d = new Demo1();
            d.showDetails();
            Console.Read();
        }
    }
}

hierarchical inheritance


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
    class Demo
    {
        public string name;
        public string loc;
        public int age;
        public string gen;
        
    }
    class Student :Demo
    {
        int marks;

        public Student()
        {

            Console.WriteLine("enter name");
            name = Console.ReadLine();
            Console.WriteLine("Enter loc");
            loc = Console.ReadLine();
            Console.WriteLine("Enter gen");
            gen = Console.ReadLine();
            Console.WriteLine("Enter age");
            age = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter marks");
            marks = Convert.ToInt32(Console.ReadLine());
        }

        public void stuDetails()
        {
            Console.WriteLine(".........................Student .............................");
            Console.WriteLine("your name is" + name);
            Console.WriteLine("your loc is" + loc);
            Console.WriteLine("your gen is" + gen);
            Console.WriteLine("your age is" + age);
            Console.WriteLine("your marks is" + marks);
        }

    }


    class Facultuy : Demo
    {
        int  salary;

        public Facultuy()
        {

            Console.WriteLine("enter name");
            name = Console.ReadLine();
            Console.WriteLine("Enter loc");
            loc = Console.ReadLine();
            Console.WriteLine("Enter gen");
            gen = Console.ReadLine();
            Console.WriteLine("Enter age");
            age = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter salary");
            salary = Convert.ToInt32(Console.ReadLine());
        }

        public void facDetails()
        {
            Console.WriteLine(".........................Falu;lty .............................");
            Console.WriteLine("your name is" + name);
            Console.WriteLine("your loc is" + loc);
            Console.WriteLine("your gen is" + gen);
            Console.WriteLine("your age is" + age);
            Console.WriteLine("your marks is" + salary);
        }

    }


    class Principal : Demo
    {
        int salary;

        public Principal()
        {

            Console.WriteLine("enter name");
            name = Console.ReadLine();
            Console.WriteLine("Enter loc");
            loc = Console.ReadLine();
            Console.WriteLine("Enter gen");
            gen = Console.ReadLine();
            Console.WriteLine("Enter age");
            age = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter salary");
            salary = Convert.ToInt32(Console.ReadLine());
        }

        public void priDetails()
        {
            Console.WriteLine(".........................prinipal .............................");
            Console.WriteLine("your name is" + name);
            Console.WriteLine("your loc is" + loc);
            Console.WriteLine("your gen is" + gen);
            Console.WriteLine("your age is" + age);
            Console.WriteLine("your marks is" + salary);
        }

    }
    class Program
    {
        static void Main(string[] args)
        {

            Student s = new Student();
            s.stuDetails();

            Facultuy f = new Facultuy();
            f.facDetails();

            Principal p = new Principal();
            p.priDetails();

            Console.Read();
        }
    }
}

Program Without Using Abstract keyword
Abstract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{


    class A
    {
        public void show()
        {
            Console.WriteLine("hi");
        }
    }


    class B:A
    {
        public void show()
        {
            Console.WriteLine("wel");
        }
    }


    class C:A
    {
        public void show()
        {
            Console.WriteLine("JAVA");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            B ob = new B();
            ob.show();

            C oc = new C();
            oc.show();

            
            Console.Read();
        }
    }
}

Program With Using Abstract keyword

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{


   abstract class A
    {
     abstract   public void show();
        
    }


    class B:A
    {
        public override void show()
        {
            Console.WriteLine("wel");
        }
    }


    class C:A
    {
        public override void show()
        {
            Console.WriteLine("JAVA");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            B ob = new B();
            ob.show();

            C oc = new C();
            oc.show();

            
            Console.Read();
        }
    }
}

Creating Object For the Abstract Class Or InterFace

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{

   abstract class A
    {
     abstract   public void show();

     public void ss()
     {
         Console.WriteLine("Welcom Rain");
     }

        
    }

    class B:A
    {
        public override void show()
        {
            Console.WriteLine("wel");
        }
    }


    class C:A
    {
        public override void show()
        {
            Console.WriteLine("JAVA");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
           A ob = new B();
            
            ob.ss();

           

            
            Console.Read();
        }
    }
}

Interface Prograam
Interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{

    interface Demo
    {
        void show10();
    }
   
    interface Demo1
    {
        void show1();
    }

    
    interface Demo2
    {
        void show2();
    }

    class A:Demo,Demo1,Demo2
    {
        public void show10()
        {
            Console.WriteLine("this is demo class method ");
        }
   
          public void show1()
        {
            Console.WriteLine("this is demo1 class method ");
        }
          public void show2()
        {
            Console.WriteLine("this is demo2 class method ");
        }

          public void show3()
        {
            Console.WriteLine("this is A method ");
        }
   
   
    }

    class Program
    {
        static void Main(string[] args)
        {
            A oa = new A();
            oa.show10();
            oa.show1();
            oa.show2();
            oa.show3();



            Console.Read();
        }
    }
    }