Monday, 29 February 2016

C#.NET --- ABSTRACT CLASS

ABSTRACT CLASS 

In general a method which is not implemented directly and its is implemented in its derived class is known as virtual method.

in general virtual means ' not real ' or ' not actual '  or which is not existed physically is known as virtual 

why virtual methods ?

for suppose if a class is inherited by several classes, but each derived class have different implementation for a single methods, in that case base is gives a chance to implement in their classes rather writing code in that method(s).

for example if a base class CAR is there and it is inherited by two sub classes they are one is BMW and another one is FORMULA _ONE 

the BMW has right hand side steering and FORMULA_ONE have left hand side steering 
there is a function in CAR class Steering()  so rather to write that method either left hand side or right hand side . it is better to set empty or virtual and implement is derived classes
for right hand side in BMW and left hand side FORMULA_ONE respectively. 

Abstract methods and Abstract classes :

Abstract method is a virtual function created with abstract keyword  i.e., it can implemented in appropriate derived class is known as abstract method 

Abstract class is a class which contain at-least  one abstract method is known as abstract class. A abstract class contains both virtual and non-virtual methods 

rules to write a abstract method or abstract class :


  • An abstract method must be created with abstract key word as functional modifier 
  • An abstract method must be placed in a abstract class only , we cannot write it in non-abstract classes
  • An abstract class contains both abstract methods and non-abstract methods 
  • we cannot create a instance for abstract classes So it must be derived by another class 
  • An abstract method must be override in derived class otherwise it will raises compilation error.
  • An  abstract method must be public type access modifier. 
  • While implementing in derived class it must use "override" keyword.
Program :


Output is :::::::




Interview Questions :

1.Can we need to write virtual keyword for abstract methods ?
ans : No need to virtual keyword ,but Although an abstract method is implicitly also a virtual method, it         cannot have the modifier virtual.

2.Where we implement  abstract methods ?
ans: all abstract methods are not provide their implementation of that method. Instead, non-abstract derived classes are required to provide their own implementation by overriding that method.

3. Can we do inheritance by abstract class 
ans: Yes, we can inheritance by abstract classes from normal classes and also abstract classes 
   
example 1 :
   abstract class A
    {
      public abstract void method1();
      public void method2()
      {
       Console.WriteLine("implemented in class A");
      }
    }
   abstract class B : A
  {
    public abstract void method3();

  }
  public class C : B
{
     public void method1()
      {
       Console.WriteLine("implemented in class C");
      }
       public void method3()
      {
       Console.WriteLine("implemented in class C");
      }
}

Here two abstract classes are available which are inheriting one by another, but it is class B responsibility to implement class A abstract method in its sub class C.

4. Can we write 










Saturday, 27 February 2016

C#.NET --- POLYMORPHISM

POLYMORPHISM 

Polymorphism is a concept of use a single method  we can provides different operations is known as polymorphism,

In general poly means many and morphism means form i.e., many forms for a single method .

Advantage :  

We can assigns some additional work to the function apart from the existing work.
We can provide different implementation to the same function or method

Suppose if a function add() do addition two number but we want addition three number with the name of add() function we can do by again writing it.

Polymorphism can be classified into two types :

1. Static Polymorphism
2. Dynamic Polymorphism


Static Polymorphism :

static polymorphism  is the polymorphism which occurs at compile time. the deciding choosing a method is done at compile time only. It is also called early  binding.

By using Function Overloading we can achieve it.

Dynamic Polymorphism :

dynamic polymorphism is the type of polymorphism which occurs at runtime only, that is choosing of which is method is decided at runtime  or execution time. It is also called late binding.

By using function overriding we can achieve dynamic polymorphism.


Function Overloading 

The mechanism of  providing different implementation to same function with different signature is called function overloading. It is a static polymorphism

we can write two or more functions with different signature. Here signature means

1. number of arguments
2. type of arguments
3. return type of function

If we write any two or more functions with same name and by changing number of arguments , type of arguments or return type of  arguments

Ex:






































Here in a same class we have wrote 3 add functions of different of signature. The compiler detects which type of function is suitable based on given parameter at compiler time.

Outpur is :





-----------------------------------------------------------------------------------------------------------


Function Overriding :

The mechanism of  providing a same function name  which is base class can write  with different implementation with same signature in derived class is called as function overriding

While doing inheritance if we want to provide different implementation for base class method we can override method by writing same function with same signature. the method choosing done at runtime 






C#.NET ---- MULTI LEVEL INHERITANCE

MULTI LEVEL INHERITANCE

Multilevel inheritance is one type of inheritance which deriving a child class from already derived parent class that is acquiring the properties of  a class which acquires some properties from another class.

Suppose class B acquired one methods form Class A, and class C acquired from class B then all properties of class A and class B of both can access by class C.

for example, a person B acquires some properties from his father A, and person is C is son of person B who can acquires his father B properties and his fathers father A properties both.



Ex :

class father    
{
  public void fProperty()
{
  Console.WriteLine("I have one big house ");
 }
}
class Person : father    // this is first level of inheritance
{
  public void pProperty()
 {
  Console.WriteLine("I have10kg gold ");
 }
}
class son : Person     // this is second level of inheritance
{
  public void sProperty()
  {
    Console.WriteLine("I have a car ");


}

}
class Program
{
 static void Main()
{
  son s = new son()
   s.fProperty();  // his father property
   s.pProperty();  // person property
   s.sProperty();   // his son property
   Console.ReadKey();
}
}

Output :
I have one house
I have 10kg gold
I have a car


---------------------------------------------------------------------------------------------------------------------

Friday, 26 February 2016

C#.NET ---- HIERARCHICAL INHERITANCE

                                                    HIERARCHICAL INHERITANCE 

Hierarchical inheritance is  one type of inheritance which is deriving two or more class from a single base class is know as hierarchical inheritance.

The same base class B1 properties are can share by different class d1, d2, d3...dn., are done here, and for each and every derived class a single copy is generated if we change the properties of a base class it cannot effect the other derived classes.


fig 1 :

fig 2: student is base class and art student , science student and commerce are derived class




A Sample example program on hierarchical inheritance ;

class Student
{
  public void print()
 {
   Console.Write("this   student ");
  }

}
class ArtsStudent : Student
{
  public void print1()
 {
    
   Console.WriteLine("is Arts student ");
  }
}
class ScienceStudent : Student
{
 public void print2()
 {
   Console.Write("is Science student ");
  }
}
class CommerceStudent : Student
{
 public void print3()
 {
   Console.Write("is Science student ");
  }
}

class Program
{
   ArtsStudent as = new ArtsStudent();   // creating object for each class 
   ScienceStudent ss = new ScienceStudent();
   CommerceStudent cs = new CommerceStudent();
   as.print();        // accessing base class method 
   as.print1();
   ss.print();
   ss.print2();
   cs.print();
   cs.print3();
    
     Console.ReadKey();
}

output is 
this student is Art student
this student is Science student 
this student is Commerce student


Program 2: another on hierarchical inheritance is here if you want to download it see below


C#.NET ---- SINGLE INHERITANCE

Single inheritance :

The process of creating one new class by derived from a single class is known as single Inheritance.

A simple example for single inheritance is father and son . a father property is can a chance to us        by son like their relationship, inheritance forms a relationship called "IS A' for suppose
 "Man is a Human ".
       base class = Human
       derived class = Man
After inheritance , A Derived class can access Base class properties , But The Base cannot have a permission to access Derived class properties 

Define a base class :

class  <BaseClassName >
{
 //data members of super class
 //methods of super class
 }

EX :
      class A
     {
        String str = "base class" ;
        public void Print()
        {
            Console.WriteLine("this is "+ str);
         }
      }

Here we write a normal class A with str as member variable and Print() member method 

Define a derived class:

Class < SubClassName> : < SuperClassName >
{
 //data members of sub class
 //methods of sub class

 }
   Ex : 
       class B : A
      {
        string str2 = "child class";
        public void print2()
       {
           print();                  // accessing Class A method with out using object
           Console.WriteLine(str2+" is derived from " + str);
        }
      }

Here By using colon ' : ' operator we can do inheritance from A to B , in Class B we can directly access Class A properties like print() method because they are inherited.


Accessing base class through derived class:

<subclassname> objectname = new  <subclassname>();

     objectname.SuperClassMethod();
                                or
     variable = objectname.SuperClassVarible ;

 Ex :
  
Class Program
{
   B b = new B(); // creating a sub class object
    b.print(); // accessing Class A method through object
    b.print2() ;

   Console.ReadKey();
}

Here we create a sub class object b and using sub class object only we can access directly the base class methods.
output  :
              this is base class
              this is base class
              child class is derived from base class

------------------------------------------------------------------------------------------------

Program 2 : 

Write a program on single inheritance like entering details in Base class and print that details in Derived class ?



/** A program on single inhertance **/
using System;
namespace InheritanceDemo
{
    class ClsParent    // creating parent class or base class
    {
        public  string source, destination; // base class variables 
        public void Reservation() // base class method
        {
            Console.Write("Enter city name where your are in now : ");
            source = Console.ReadLine();
            Console.Write("Enter city name where you need to go : ");
            destination = Console.ReadLine();
        }
    }
    class ClsChid : ClsParent  // creating child class using : colon operator
    {
         double amount;
        public void calAmount() // derived class method
        {
           
            amount=1000;
        }
        public void DisplayReservationDetails() // derived class method
        {
            Console.Write("\nfyour are  travling from "+source); // source is accessible because it is inherited from parent class
            Console.WriteLine(" to "+destination);  // destination is accessible because it is inherited from parent class
            Console.WriteLine("fare is :"+amount);   // amount is child class variable only             
        }
   
    }
    class Program
    {
        static void Main(string[] args)
        {
            ClsChid obj = new ClsChid(); // creating object for derived class
            obj.Reservation();   // using derived class object accessing base class method 
            obj.calAmount();        // as usual accesing member methods 
            obj.DisplayReservationDetails(); // as usual accessig member methods
            Console.ReadKey();
        }
    }
}

Output :
Enter city name where you are in now : hyderabad 
Enter city name where yor need to go : vijayawada

your are  travling from hyderabad to vijayawada
face is : 1000








------------------------------------------------------------------------------------------




       



Thursday, 25 February 2016

C#.NET ----- INHERITANCE

Inheritance:

Inheritance is a process of acquiring of the properties from one class to another class that is creating a new class by deriving properties from existing class.

Advantage :  
 we can reuse one class methods and variables without creating same methods and variable again and again. By doing like this we decrease length of program very easily.

We are creating a child class by inheriting the parent class properties, and we can also add some  features to child class.

Parent Class :
 The base class which is already created and gives its properties to derived class is known parent class or base class or super class.

Child Class   :  
The derived class which is takes the properties form already exists base class is known as Child class or derived class or sub class.




In OOP System there are five types of Inheritance are available . they are

  1. Single Inheritance
  2. Hierarchical Inheritance
  3. Multi Level Inheritance
  4. Multiple Inheritance
  5. Hybrid Inheritance 

Single Inheritance:
Creating one new class by deriving properties that is methods and variables from single base class.
It is a simple type of inheritance.



Hierarchical Inheritance:
Creating two or more sub classes from single base class is known as Hierarchical Inheritance.



Multi level Inheritance:
Creating a sub class from already derived class is known as Multi Level Inheritance.



Multiple Inheritance:
Creating a new class by deriving from two or more class is known as Multiple inheritance.



Hybrid Inheritance:
It is combination of any two type of Multi level inheritance,Hierarchical inheritance and Multiple Inheritance, It is rare type of inheritance used in practical.


Note: Other OOP languages like C++ support multiple inheritance and hybrid inheritance. But C# and VB.NET doesn‘t support multiple inheritance and hybrid inheritance to avoid some practical problems while developing future GUI applications like windows forms applications, web sites etc.




--------------------------------------------------------------------------------------------------------------------------

Wednesday, 24 February 2016

C# ----- OOPS Concepts starting

Object Oriented Programming System

 Object Oriented Programming System :


The main intention of object oriented concept is reusability of existing code, providing security for data, decreasing the code complexity i.e., basing on object requirement we coding and executing programs is main purpose of OOPS 

Before OOPS there is Structure Oriented Programming languages are used to develop programs, the limitations of structure oriented programming languages are  no reusability concept  and there is no security for data . to retrieve the limitations OOPS concept is invited.

What are the limitations of Structure Oriented system  ?

  • Less security for data 
  • There is no  reusability concepts 
  • There is more code complexity 
  • There is no exception handling 

There are four main pillars of OOP System,  they are :
  1. Data Abstraction 
  2. Data Encapsulation
  3. Inheritance 
  4.   Polymorphism

These main concepts contains in OOP system

Data Encapsulation :

The process of binding data into a single container is known as data encapsulation.
Here data means methods and variables and those are binding in a container, here we called CLASS

What is Class ?
Class is a collection of objects which contains some common features and functionalities.
Class is a combination of member methods and member variables.
Simply in one word class is blueprint for objects.
Ex ; animal is class for dog , cat , goat

What is Objects ?
Object is an instance of class and it is a real world entity which exists physically in world.
Ex : car is class and
       Objects are BMW, Audi, Honda etc. there is exists in market.
Without objects there is no class like without students there is no Class like cse class, civil class.

SYNTAX for creating a Class:

<access-modifier> class <class-name>
{
 Member methods ;
Member Variables ;
}

Ex : 
  public class MyClass  // user defined class
{
  string s="DotNet " ;         // member variable
  public void print()   // member method
 {
   Console.WriteLine("Hello ,"+s);
  
 }
}

SYNTAX for creating a Object :

<class-name> <object-name> = new <class-name>(parameters);

ex :
      class EntryClass
     {
       static void Main()
      {
        MyClass object = new MyClass();  // creating an object 
        
         object.s = "ramu";  // accessing methods variable through object 
         object.print();    // accessing member methods through object 
        
         Console.ReadKey();
     
     }

Data Abstraction :

    Hiding of data is known as Data Abstraction. i.e., Hiding the implementation and providing user required information only. 
The nature of  "instance" creation is also known as "Data Abstraction".

Access modifiers :

The permissions can be given to the object to access the class members from outside of the class using  "access modifiers ".


So hiding of data is data abstraction for example in ATM machine it shows how to put card , how to withdraw money , how to check balance (which is need to people)only But It doesn't display how to collect money in machine, how to edit our balance in our account. that is it shows whatever information required (which is not required for user )only.



 --------------------------------------------------------------------------------------------------------------------







Tuesday, 23 February 2016

C#.NET --- Sample Programs on Console Class

Sample programs in C#.NET

Lets us see one sample program which can utilize System.Console class

Console is class which contains input and output possible methods and it is in System namespace

Steps to write and execute a sample programs
Step 1 : open visual studio 2012
Step 2 :  goto file => new = > project
Step 3 : select C# language , select  .NET framework 4.5 and select “console applicatiom ” template .
Step 4 : Write project name as ConsoleDemo and click OK
Step  5  : Write the following code shown below 

using System; // importing section
namespace ConsoleDemo2  // namespace begining 
{
    class Program       // a class begining
    {
        static void Main(string[] args)  // method begining 
        {
            Console.Write("hi ,");
            Console.WriteLine("Mr. DOTNET ");
            Console.WriteLine("hello C#.NET");// prints output black screen
            Console.ReadKey();  // it awaits until we press any single screen
        }
    }
}

Step 6: Now build the project by going to BUILD menu select Build Solution and Click START
Step 7: If the code have no error . it will shows the output as below 

 Console class methods and properties

Methods :
  1. write() : It prints characters to the black screen 
  2. WriteLine() : It prints characters to the black screen and moves cursor to new line
  3. Read() : It reads a character from screen and written ASCII value of the char
  4. ReadLine() : It reads a string value and returns string
  5. ReadKey() : It reads a single character or it waits for taking single character
  6. Clear() : it wil clears black scree
  7. Beep() : it gives beep sound
Properties :
  1. backGroundColor
  2. foreGroundColor
  3. title
  4. windowSize
  5. cursorSize etc.,
If you want see remaining methods and properties while write Console. and press ctrl+space
the intelligence shows remaining methods and properties

C#.NET ----- C# language introduction

C#.NET language introduction 


C#.NET is programming language developed by Microsoft pvt ltd company .

C# is most powerful language among all programming languages in .NET because it inherits form C, C++, java and other languages.

C#.NET is mostly used programming language now .
C#.NET developing team lead by “Anders Hegelburg”.
The most recent version of C#.NET is C# 6.0 which is released in July 2015
C# will provides good GUI features
C# will interact with several data base servers like ADO.NET
C# will also prepares web applications using web side technologies like ASP.NET .

Visual studio 2012

Visual studio is IDE ( Integrated Development Environment ) for .NET applications . by using this visual studio we can write program code , we can compile that code and we can execute that code 



There are so many versions of visual studios there 
  • visual studio 2002
  • visual studio 2003
  • visual studio 2005
  • visual studio 2008
  • visual studio 2010
  • visual studio 2012
  • visual studio 2013
  • visual studio 2015
Now i am using visual studio 2012.
After initialization of  visual studio 

How to programming in visual studio 

step 1 : in start menu type 'devenv' or directly open visual studio 2012 in All programs
step 2 : It will open a window like this 


step 3: goto file => new => project it will open a new window 



Step 4 : Write in name filed SampleApplication and click ok 
step 5 : It will open a new window with predefined program and write below code 


Using :
 It is keyword for to import all  class libraries 

Namespace : namespace is collections of  class and sub namespaces 

class  : in object oriented languages class is compulsory to write a programs , it contain methods and variables 

Main() : main is user defined special method which acts as entry point of program 


NOTE : Every line C# programming end with semicolon ';'






















Monday, 22 February 2016

C#.NET ------ Execution flow in .NET

Execution flow in  .NET 


The execution flow in .NET contains
1. Source Code : The code we have written using one language like C#,NET, VB.NET

2. Language Compiler :
    compiler is software which check the rules and regulation and executes the program
every programming languages have their own compiler like C#.Net compiler

3.MSIL (Microsoft Intermediate Language ) :
 Different language compiler converts into BYTE CODE . one language compiler BYTE CODE cannot understand  by other language . So to provide interoperatability  all BYTE CODE convert into a common CODE is MSIL which understand by all .NET languages

Regardless of the language we use to develop our .NET applications , all languages applications are compiled to the MSIL BYTE CODE

4.CLR (Common Language Runtime) :
  CLR is the completely responsible to manage the .NET applications at runtime .
It provides core services such as memory management , thread management , exception handling , security and resource management.

  the basic components of  CLR

  1. Common Language Specification
      In general one language specification cannot understand by another language . CLS provides some common rules and regulations to all .NET languages . that rules are same to all languages.
   
 II Common Type System  
  In general one language data types are not understand by another data type system . So CLS convert all languages data types into its common type system data types  which understand by all languages.
 III.Garbage Collector 
   The main responsibility of garbage collector is automatic memory management . i.e., the process of deallocating memory of inactive objects or unused object.

  IV JUST IN TIME compiler 
  JIT compiler is responsible for converting MSIL CODE into native code which is understand fastly understand by Operating system and processor

5. Native Code :
   The code which is zeros and ones and fastly understand by execution environment

6 Execution environment 

   execution environment is combination of  processor and operating system




TYPES OF APPLICATIONS Developing using .NET

1 Console Applications
2 Window services
3 Web Applications
4 Web Services
5 mobile applications
6 Window Form Application
7 WPF applications











C#.NET -------- Introduction to C#.Net

.NET or DOTNET means NETwork enable Technology,

Actually, these is no abbreviation for .NET but it just tells that .NET means a network enable technology i.e., by using of .NET we can network.

What is .NET ?

.NET is not a programming language
.NET is not a technology
.NET is not a ERP tool
.NET is not a Data base query language

.NET is framework tool which supports multiple languages
.NET is platform for  interaction of more languages and more technologies

A framework is the combination of libraries (DLLs) and runtime (CLR) i.e., a framework provides a predefined libraries to support program languages
A platform is the combination of  operating system architecture and process architecture.

Language : It acts as interface between the programmer and the system.
language offers some rules and regulations for writing the programs and it also offers some libraries
which is required for writing the programs.
Ex : C#.NET , C , C++, JAVA, VB.NET

Technology : It doesn't offer any specific rules for writing the programs But it offers some libraries.
It requires a language for the rules to write the programs.e
ex : ASP.NET , ADO.NET
Platform Dependent : The code that is generated after language compilier compilation dosn't run on different platform

Platform Independent : The code that is generated after language compilier compilation does run on different platforms.

Why .NET ?
.NET supports so many features they are
1. Platform independent language
2. Language interoperatability (coverting one language code into another languages )
3. Object Oriented Programming System.
4. Robust language
5. It gives own IDE (ms visual studio)
6. It gives network communicated applications



Sunday, 21 February 2016

C#.Net --- creating DLL files in c#

  DLL means Dynamic Linked Library. the dll is supportive file which gives a pre-defined 
methods to executable file. by using dll file we can reduce code complexity 
  The DLL are major part of BCL( base class library) which is one of component of .NET framework.(another part is CLR common language Runtime)
  if a program generate a execution file with extension '.exe' is exe file 
     a program generate a support file with extension '.dll'  is know as dll file .

 the dll files acts as libraries which contains one or more pre defined methods 
 the methods are used later where we want .
for examples :
       In a college, a library contains so many books by using these books we read or write or do anything what we want 

if we are creating dll means  we can use these methods in another project without deriving that class like with out doing inheritance 

How to Create a DLL file

    => open visual studio and 
      => select file->new->project
       => in project window select -> c# and select template "class library file" instead of Console Application
                            give a name like MathOperations and click ok
        => it will generate a new project with out main method . and type the following 
code 

After executing this program your can see in computer a dll file created in project path C:/dotnet/MathOperations/MathOperations/bin/debug/'-------here a file with MathOperations.dll name will created .