C# console applications

BASIC PROGRAM  1

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

namespace basicprogramming
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            Console.WriteLine("the value of a" +" " + a);
            Console.WriteLine("this is my first consol program");
            Console.WriteLine("welcome to my program");
            Console.ReadKey();//break to output screen 
        }
    }
}

BASIC PROGRAM  2: INPUT FROM USER

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

namespace userinputpro
{
    class Program
    {
        int a;
        void accept()
        {
            Console.WriteLine("enter any number");
            a = int.Parse(Console.ReadLine());

            Console.WriteLine("the value of a is" + " " + a);
        }
        static void Main(string[] args)
        {
          
            Program p1 = new Program();
            p1.accept();
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  3: USING FUNCTION( )/PARAMETER PASSING

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

namespace fun1
{
   
    class Program
    {
        //create function
        int b;
        void accept(int a)
        {
            b = a;
        }
        void show()
        {
            Console.WriteLine("the vaue of b is " + " " + b);
        }

        static void Main(string[] args)
        {
            //classname object=new classname();
            Program p1 = new Program();
            //object.functionname()
            p1.accept(10);
            p1.show();
            Console.ReadKey();
        }
    }
}


BASIC PROGRAM  4: DATA DISPLAY USING FUNCTION( )/PARAMETER PASSING

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

namespace data_display_using_function
{
    class Program
    {
        string b,c,d,e,h;
        int f,g;
        void input1(string name, string city, string state, string subject, int age, int sem, string mobile)
        {
            b = name;
            c = city;
            d = state;
            e = subject;
            g = sem;
            h = mobile;
            f = age;
            
            if (age > 18)
            {
                display();
            }
            else
            {
                Console.WriteLine("you are not eligible");
            }
        }
        void display()
        {
            Console.WriteLine("Your name is :" + " " + b);
            Console.WriteLine("Your city name is: " + " " + c);
            Console.WriteLine("your state name is :" + " " + d);
            Console.WriteLine("your subject name is: " + " " + e);
            Console.WriteLine("your age is :" + " " + f);
            Console.WriteLine("your semester is :" + " " + g);
            Console.WriteLine("your mobile number is :" + " " + h);
        }
        static void Main(string[] args)
        {
            Program p1 = new Program();
            p1.input1("rucha", "Nagpur","Maharashtra","BE",29,5,"8698408800");
          
            Console.ReadKey();

        }
    }
}
OUTPUT:
Your name is : rucha
Your city name is:  Nagpur
your state name is : Maharashtra
your subject name is:  BE
your age is : 29
your semester is : 5
your mobile number is : 8698408800

BASIC PROGRAM  5: IF ELSE CONDITION

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

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

           
            Console.WriteLine("Enter your name");
            string name = Console.ReadLine();
          
           
            Console.WriteLine("Enter your class");
            string class1 = Console.ReadLine();
          
            Console.WriteLine("Enter your semester");
            string Sem = Console.ReadLine();
         
            int tottalatt;
            Console.WriteLine("Enter your total attendance");
            tottalatt = int.Parse(Console.ReadLine());
            if (tottalatt > 90)
            {
                Console.WriteLine("Student name:" + "  " + name);
                Console.WriteLine("Class:" + " " + class1);
                Console.WriteLine("semester:" + " " + Sem);
                Console.WriteLine("Total attendance:" + " " + tottalatt);
                Console.WriteLine("your scholarship approved");
            }
            else
            {
                Console.WriteLine(" Your scholarship not approved");
            }
            Console.ReadKey();
        }
    }
}
OUTPUT:
Enter your name
Riya
Enter your class
BE
Enter your semester
VII
Enter your total attendance
91
Student name:  Riya
Class: BE
semester: VII
Total attendance: 91
your scholarship approved

BASIC PROGRAM  6: IF ELSE CONDITION

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

namespace elseifcon
{
    class Program
    {
        static void Main(string[] args)
        {
            int per;
            Console.WriteLine("Enter your percentage");
            per = int.Parse(Console.ReadLine());
            if (per > 60)
            {
                Console.WriteLine("Result:First division");
            }
            else if (per > 50 && per<60)
            {
                Console.WriteLine("Result:Second division");
            }
            else if (per > 40 && per < 50)
            {
                Console.WriteLine("Result:Third division");
            }
            else
            {
                Console.WriteLine("Result:Fail");
            }
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  7: IF ELSE CONDITION


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

namespace condition1
{
    class Program
    {
        static void Main(string[] args)
        {
            int age;
            Console.WriteLine("Enter your age");
            age = int.Parse(Console.ReadLine());
            if (age > 18)
            {
                Console.WriteLine("you can go");
            }
            else
            {
                Console.WriteLine("you cannot go");
            }
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  8: SWITCH CASE

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

namespace switch1
{
    class Program
    {
        static void Main(string[] args)
        {
            int ch;
            
            Console.WriteLine("Enter your choice");
            ch = int.Parse(Console.ReadLine());
            switch (ch)
            {
                case 1: Console.WriteLine("you press 1");
                    break;
                case 2: Console.WriteLine("you press 2");
                    break;
                case 3: Console.WriteLine("you press 3");
                    break;
                default: Console.WriteLine("invalid choice");
                    break;
            }
            Console.ReadKey();
        }

    }
}

BASIC PROGRAM  9: LOOPING

WHILE

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

namespace while1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i=0;

            while (i <= 10)
            {

                Console.WriteLine(i);
                i++;
                
            }
            Console.ReadKey();
        }
    }
}

DO WHILE

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

namespace dowhile1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            do
            {
                Console.WriteLine(i);
                i++;

            } while (i <= 10);
            Console.ReadKey();
        }
    }
}

FOR

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

namespace for1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            for (i = 1; i <= 10; i++)
            {
                Console.WriteLine(i);
            }
            Console.ReadKey();


        }
    }
}

BASIC PROGRAM  10: IF ELSE CONDITION

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

namespace resultprint
{
    class Program
    {
        static void Main(string[] args)
        {
            int s1;
            Console.WriteLine("Enter marks of Marathi");
            s1 = int.Parse(Console.ReadLine());
            int s2;
            Console.WriteLine("Enter marks of English");
            s2 = int.Parse(Console.ReadLine());
            int s3;
            Console.WriteLine("Enter marks of Science");
            s3 = int.Parse(Console.ReadLine());
            int s4;
            Console.WriteLine("Enter marks of Maths");
            s4 = int.Parse(Console.ReadLine());
            int s5;
            Console.WriteLine("Enter marks of Social science");
            s5 = int.Parse(Console.ReadLine());
            int total; 
            total= s1 + s2 + s3 + s4 + s5;
            if (total > 200)
            {
                Console.WriteLine("Marahi:" + "  " +s1);
                Console.WriteLine("English:" + " " +s2);
                Console.WriteLine("Science:" + " " +s3);
                Console.WriteLine("Maths:" + " " +s4);
                Console.WriteLine("Social science:" + " " + s5);
                Console.WriteLine("Total Marks:" + " " +total);
                Console.WriteLine("Result remark: A  Grade");
            }
            else
                if (total > 150 && total < 200)
                {
                    Console.WriteLine("Marahi:" + "  " + s1);
                    Console.WriteLine("English:" + " " + s2);
                    Console.WriteLine("Science:" + " " + s3);
                    Console.WriteLine("Maths:" + " " + s4);
                    Console.WriteLine("Social science:" + " " + s5);
                    Console.WriteLine("Total Marks:" + " " + total);
                    Console.WriteLine("Result remark: B  Grade");
                }
                else
                {


                }
               
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  11: IF ELSE CONDITION


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

namespace emplo
{
    class employee
    {
        string name, city;
        int sal;
        public void accept(string name1,string city1,int sal1)
        {
            name = name1;
            city = city1;
            sal = sal1;
            display();
        }
        void display()
        {
            Console.WriteLine("your name is"+" " + name);
            Console.WriteLine("your city is city"+" " + city);
            Console.WriteLine("your salary is"+" " + sal);

            if (sal > 5000)
            {
                Console.WriteLine("employee designation: manager");
            }
            else
            {
                Console.WriteLine("employee designation: supporting staff");
            }

        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            string n, c;
            int s;
            Console.WriteLine("enter your name");
            n = Console.ReadLine();
            Console.WriteLine("enter your city");
            c = Console.ReadLine();
            Console.WriteLine("enter your salary");
            s = int.Parse(Console.ReadLine());
            employee p1 = new employee();
            p1.accept(n,c,s);
            Console.ReadKey();

        }
    }
}

BASIC PROGRAM  12: CLASS OBJECT

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

namespace classo
{
    //create a user class
    class one
    {
        public void display()   //here function() is called as method
        {
            Console.WriteLine("this is my first class");//console.writeline is a output statement

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //classname objname=new classname();
            one p1 = new one();
            //synatx for access method- objname.methodname();method() can appear in list when it decalre as public method(),here public void display() is a method
           p1.display();

            Console.ReadKey(); //it is used to break output screen.

        }
    }
}

BASIC PROGRAM  13: CLASS OBJECT PARAMETER PASSING

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

namespace calssoparameter
{
    class one
    {
        public void display(int A)// here A is areceiver parameter
        {
            Console.WriteLine("the value of A is" + " " + A);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            one p1 = new one();
            p1.display(20);//sender parameter
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  14: CLASS OBJECT PARAMETER 


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

namespace classobjprivate
{
    class one
    {
       public void display()
        {
            Console.WriteLine("this is my first function");
            show();
        }
       void show()
       {
           Console.WriteLine("this is show function");
       }
    }
    class Program
    {
        static void Main(string[] args)
        {
            one p1 = new one();
            p1.display();
            Console.ReadKey();
              
        }
    }
}

BASIC PROGRAM  15: CLASS OBJECT USING STRUCTURE

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

namespace struct1
{
    class Program
    {
        struct employee
        {
           public int eid;
            public string name;


        };

        static void Main(string[] args)
        {
            //synatx for stucture object
            //structre name object name;
            employee e1;
            Console.WriteLine("enter employee id");
            e1.eid = int.Parse(Console.ReadLine());
            Console.WriteLine("enter your name");
            e1.name = Console.ReadLine();
            Console.WriteLine("your employee id is:-" + " " + e1.eid);
            Console.WriteLine("your name is:-"+" "+e1.name);
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  16: CLASS OBJECT USING STRUCTURE

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

namespace structstudent
{
    class Program
    {
        struct student
        {
            public string name;
            public string city;
            public string state;
            public int mark1;
            public int mark2;
            public int mark3;
            public int mark4;
            public int mark5;


        };
        static void Main(string[] args)
        {
            int total;
            student s1;
            
            Console.WriteLine("enter your name");
            s1.name = Console.ReadLine();
            Console.WriteLine("enter your city");
            s1.city = Console.ReadLine();
            Console.WriteLine("enter your state");
            s1.state = Console.ReadLine();
            Console.WriteLine("enter mark1");
            s1.mark1 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter mark2");
            s1.mark2 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter mark3");
            s1.mark3 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter mark4");
            s1.mark4 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter mark5");
            s1.mark5 = int.Parse(Console.ReadLine());
            total = s1.mark1 +s1.mark2 + s1.mark3 + s1.mark4 + s1.mark5;
            if (total > 500)
            {
                Console.WriteLine("Mark1:" + "  " + s1.mark1);
                Console.WriteLine("Mark2:" + " " + s1.mark2);
                Console.WriteLine("Mark3:" + " " + s1.mark3);
                Console.WriteLine("Mark4:" + " " + s1.mark4);
                Console.WriteLine("mark5:" + " " + s1.mark5);
                Console.WriteLine("Total Marks:" + " " + total);
                Console.WriteLine("Result remark: First division");
            }
            else
                if (total > 300 && total < 500)
                {
                    Console.WriteLine("Mark1:" + "  " + s1.mark1);
                    Console.WriteLine("Mark2:" + " " + s1.mark2);
                    Console.WriteLine("Mark3:" + " " + s1.mark3);
                    Console.WriteLine("Mark4:" + " " + s1.mark4);
                    Console.WriteLine("mark5:" + " " + s1.mark5);
                    Console.WriteLine("Total Marks:" + " " + total);
                    Console.WriteLine("Result remark:  second division");
                }
            else

            if (total > 200 && total < 300)
            {
                Console.WriteLine("Mark1:" + "  " + s1.mark1);
                Console.WriteLine("Mark2:" + " " + s1.mark2);
                Console.WriteLine("Mark3:" + " " + s1.mark3);
                Console.WriteLine("Mark4:" + " " + s1.mark4);
                Console.WriteLine("mark5:" + " " + s1.mark5);
                Console.WriteLine("Total Marks:" + " " + total);
                Console.WriteLine("Result remark: Third division");
            }
            else
                {
                    Console.WriteLine("Result remark: Fail");
                }

            
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM  17: CLASS OBJECT USING STRUCTURE & FUNCTION

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

namespace funcstruct22
{
    class employee
    {
        string name, city,state;
        int sal;
        public void accept(string name1, string city1,string state1, int sal1)
        {
            name = name1;
            city = city1;
            state = state1;
            sal = sal1;
            display();
        }
        void display()
        {
            Console.WriteLine("your name is" + " " + name);
            Console.WriteLine("your city is " + " " + city);
            Console.WriteLine("your state is" + " " + state);
            Console.WriteLine("your salary is" + " " + sal);

            if (sal > 5000)
            {
                Console.WriteLine("employee designation: manager");
            }
            else
            {
                Console.WriteLine("employee designation: supporting staff");
            }

        }

    }

    class Program
    {
        struct emplo
        {
           public string name;
            public string city;
            public string state;
            public int salary;

        };
        static void Main(string[] args)
        {
            emplo e1;
            Console.WriteLine("enter your name");
            e1.name = Console.ReadLine();
            Console.WriteLine("enter your city");
            e1.city = Console.ReadLine();
            Console.WriteLine("enter your state");
            e1.state = Console.ReadLine();
            Console.WriteLine("enter your salary");
            e1.salary = int.Parse(Console.ReadLine());
            
            employee p1 = new employee();
            p1.accept(e1.name,e1.city,e1.state,e1.salary);
            Console.ReadKey();

        }
    }
}


BASIC PROGRAM  18: INHERITANCE



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

namespace inheritance1
{
    class one
    {
        public void display()
        {
            Console.WriteLine("this is my first class");
        }
    }
    class two : one //this is called inheritance
    {
       public void show()
        {
            Console.WriteLine("this is class two"); 
        }
    }

    class three: two
    {
       public  void print()
        {
            Console.WriteLine("this is third class");
        }
    }

   class Program
    {

        static void Main(string[] args)
        {
           // two t1 = new two();  //only last class object createsa
            three t1 = new three();
            t1.print();
            t1.display();
            t1.show();
            Console.ReadKey();
            
        }
    }
}

BASIC PROGRAM  19: ABSTRACT 

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

namespace abstractexample
{
   abstract class one
    {
        public void display()
        {
            Console.WriteLine("this is my display function");
        }
    }
    class two : one //one is an abstract class
    {
        public void show()
        {
            Console.WriteLine("this is my second class");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            two t1 = new two();
            t1.display();
            t1.show();
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM 20: FUNCTION OVERLOADING

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

namespace funover
{
    class one
    {
        public void display()
        {
            Console.WriteLine("this is my first program");
        }

        public void display(int a)
        {
            Console.WriteLine("the value of a"+" "+a);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            one o1 = new one();
            o1.display();
            o1.display(10);
            Console.ReadKey();
             
        }
    }
}

BASIC PROGRAM 21: INTERFACE

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

namespace interface1
{
     interface one
    {
        void display();//declare function
    }
    class my : one
    {
        public void display()
        {
            Console.WriteLine("this is my first display");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //create object
            my m1 = new my();
            m1.display();
            Console.ReadKey();

        }
    }
}

BASIC PROGRAM 22: MULTIPLE INHERITANCE

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

namespace multiple_inheritance_using_multiple_interface
{
   
     interface one
    {
        void display();//declare function
    }
     interface two
     {
         void show();
     }
    class my : one, two //this is multiple inheritance using multiple interface 
    {
        public void display()
        {
            Console.WriteLine("this is my first display");
        }
        public void show()
        {
            Console.WriteLine("this is my show function");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //create object
            my m1 = new my();
            m1.display();
            m1.show();
            Console.ReadKey();

        }
    }
}

BASIC PROGRAM 23:TRY ,CATCH & FINALLY

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

namespace exception_try_cacth_finally
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10, b = 0, c;
            try
            {
                c = a / b;
                Console.WriteLine(c);
            }
            catch (Exception e1) //e1 is a exception object return in error
            {
                Console.WriteLine(e1);
            }
            finally
            {
                Console.WriteLine("this is my try catch program");
            }
            Console.ReadKey();
        }
    }
}

BASIC PROGRAM 24:ABSTRACTION


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

namespace salaryabstract
{
    
    abstract class employee
    {
        
        public void accept()
        {
          int sal;
          Console.WriteLine("enter your salary");
          sal = int.Parse(Console.ReadLine());
          Console.WriteLine("your salary is:-" + " " + sal);
        }
    }
    class HR : employee
    {
        string name, department, designation, email, mobile;
        public void input()
        {
            Console.WriteLine("Name :-" + " " + name);
            Console.WriteLine("Name :-" + " " + department);
            Console.WriteLine("Name :-" + " " + designation);
            Console.WriteLine("Name :-" + " " + email);
            Console.WriteLine("Name :-" + " " + mobile);

        }
        public void display()
        {

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            string n, d, ds, e, m;
            Console.WriteLine("enter your name");
            n = Console.ReadLine();
            Console.WriteLine("enter your department");
            d = Console.ReadLine();
            Console.WriteLine("enter your designation");
            ds = Console.ReadLine();
            Console.WriteLine("enter your email");
            e = Console.ReadLine();
            Console.WriteLine("enter your mobile");
            m = Console.ReadLine();
            HR h1 = new HR();
            h1.accept();
            h1.input(n,d,"ds",e,m);
            h1.display();
            Console.ReadKey();

            

        }
    }
}

Comments

Popular posts from this blog

DATATABLES

MVC(MODEL-VIEW-CONTROLLER)