C# Concepts

Dot Net

Dot net is form base environment. It s a multi language support system.It works on JIT i.e.Just in time which is working on event whereas C programming compiler working on group.

Environment

  1. Console:- It supports to all basic programming fundamentals.
  2. Web:- for web development environment
  3. Window/Desktop :- for window development environment

Console Application(C#):- Object oriented Programming

Windows in Microsoft visual  studio 2010 tool:-

1.Solution Explorer:- Represent all file folder or library.
2.Sever explorer :- Represents all the information from database.
3.Tool Box:- Representing Tools
4.Property window:- Represents information of current working area

How to open console application project:-
step 1:- start the Microsoft visual studio 2010
step 2:- file
step 3:- select other language VB C#(at left corner)
step 4:- select console application visual c#
step 5:- give project name 

Some basic points:-
1.Output statement:- Console.WriteLine("   ");
2. How to beak output screen :- Console.ReadKey();
3. ReadKey always use at the end of the program.
4.All purple color keywords are representing function i.e.( )
5.User input statement:- Console.ReadLine used for read the statement 

FUNCTION

1.Function is a small job program. All functions are created before the main. 
2.All functions is to be access in side the main body using object.
3.All object create inside the main body.
Syntax:-
Class name objname=new Classname();
where, new -> Memory allocation 
Syntax for access function:-
objectname.functionname();

*Object Oriented Property

  • Object oriented programming is used to class structure
  • Main class cannot be count in OOPs.
  1.  INHERITANCE
  2.  CONSTRUCTOR
  3.  INTERFACE
  4.  POLYMORPHISM
  5.  ENCAPSULATION
  6. ABSTRACT CLASS
  7.  VARIABLE PROPERTY
  8.  COLLECTION CLASSES
  9.  EXCEPTION HANDLING
  10.  FILE HANDLING
  11.  OPERATOR OVERLOADING
  12.  CLASS SECURITY

How to create class and object

*What is class?
Class is a collection of member(all variable) and method(all function)

*How to access Class Method
1.With the help of object we can access all class member and method

2.Object is to be create inside the main function/body

SYNTAX
classname objname=new classname();

main is not included in oop

*How to access method using object 

SYNTAX

objname.methodname();

*All methods inside the class is private.
*In access point of view all method is converted (public)

*How to pass parameter in class

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

namespace ConsoleApplication1
{
    //create a user class
    class one
    {
        public void display(int A)// A is a receiver parameter
        {
            Console.WriteLine("The value of a"+A);    
            //console.writeline is an output statement 
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //classname objname = new classname();
            one obj1 = new one();
            //objname.methodname();
            obj1.display(20);// sender parameter
            Console.ReadKey();//break the output screen

            

        }
    }
}


**How to access private method using class and object**

RULES - Private method only access inside the public method of the class

STRUCTURE 

1. Collection of multi type data element
2. Structure is to be created using struct keyword
3. All variable inside the structure declare as a public
4. all structures is to be created before the main class
5.structure is used as self block in a computer memory so that all structure members access inside the main body using structure object.After structure closing bracket, there must be ;
6.structure is used to manage the memory

syntax
struct name obj name;

INHERITANCE

  • Inheritance is a reusability of class.
  • Inheritance is work on multiple classes
  • In inheritance main class cannot be count.
Types of Inheritance
1. Single Inheritance
2.Multilevel Inheritance.

C# cannot use multiple Inheritance and multilevel Inheritance cannot use.

*Single Inheritance:- Only one base class and one derived class.
*There are two classes in Inheritance :- Base class and Derived class
*Top of the class is called base class
*In Inheritance,create only last class object.

Syntax:- derive class: base class

Multilevel inheritance:- in this inheritance,each and every derived class access to previous class.

eg. class A


 
 class B:A



  class C :B

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();
            
        }
    }
}


example 2:-

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();

            

        }

    }

}

Class security:-

  1. In class security we have to use Abstract Method.
  2.  Abstract class is to be declare using abstract keyword.
  3. Abstract class cannot create object
  4. Abstract class only inherit the other class 

Function Overloading

Function overloading is a concept where function name are similar but activities are different.
show()
{

}

show(int a)
{

}

show(int b ,int c)
{

}


EXAMPLE:

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();
             
        }
    }
}

**Interface**

  • Interface is similar to abstract class
  • it contains the empty body of a function

 RULES
1. Interface is created using interface keyword
2. Inside the interface only method(function) is declared

eg.
interface my
{
void display(); only function declare
}

3. Inside the interface not use access specifiers (public, private etc)
4.All interface function define inside the class
5.Interface access inside the class using : symbol

 
**How to implement multiple inheritance using interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication7
{
    interface one
    {
        void display();// only declare function
    }
    interface two
    {
        void show();
    }
    class my : one,two //Implementation of multiple inheritence
    {
        public void display()
        {
            Console.WriteLine("This is my interface function");
        }
        public void show()
        {
            Console.WriteLine("This is my second interface function");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //create object
            my my1 = new my();
            my1.display();
            my1.show();
            Console.ReadKey();
        }
    }
}

 

Exception Handling

Exception Handling is return in logical errors in your program is called exception
There are following statements used in exception
1. try catch
2. finally
3. throw
 

Try catch - there are 2 block activate 1. try 2. catch

All types of logics are created inside try block
If generate the error in try block then return all exception using catch block
eg.
try
{
 a=10,b=0,c;
 c=a/b
}
catch()
{
arithmatical error
}
all types of error stored in exception class
 
Example:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication8
{
    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 an exception object returning the error
            {
                Console.WriteLine(e1);
               
            }
            Console.ReadKey();
        }
    }
}
 

 Finally statement

  • Finally is automatically executed after the catch block
  • finally is generally used to display the program comment
 



Comments

Popular posts from this blog

C# console applications

DATATABLES

MVC(MODEL-VIEW-CONTROLLER)