Tuesday, 11 August 2015

Inheritance in c# and types of inheritance.

Inheritance makes programs simpler and faster. With inheritance, we build several types upon a common abstraction. Then we later act upon all those types through the abstraction. We examine inheritance and polymorphism in the C# language.
Base class:The class another class inherits from. In the C# language, the ultimate base class is the object class.
Object
Derived class:The class with a base class. A derived class may have multiple levels of base classes.

Example. When you specify that a class derives from another class, the class you create acquires all the features of the base class. If the derived class has a few extra features but is otherwise the same as the base class, this is a good approach.
Also:By using a base class, you can treat derived classes as the same base type and call virtual functions to access their features.
Program using base class, virtual method: C#

using System;
using System.Collections.Generic;

class Net
{
    public virtual void Act()
    {
    }
}

class Perl : Net
{
    public override void Act()
    {
 Console.WriteLine("Perl.Act");
    }
}

class Python : Net
{
    public override void Act()
    {
 Console.WriteLine("Python.Act");
    }
}

There are different types of inheritance in c#.net
and these are:-
1)single inheritance.
2)multilevel inheritance.
3)hierarchical inheritance.
4)hybrid inheritance.
5)multiple inheritance.

multiple inheritance and hybrid inheritance not support in c#.
so we use interface.

Saturday, 8 August 2015

polymorphism

Polymorphism provide facility by which we can use two or more than two funtion within same name in a class. we can achieve polymorphism using two technique;

funtion overloading:

It provide facility by which we can write two or more than two functions having same name withy different signature in a single class or in derived class.

funtion overriding

It provide facility by which we can write two or more than two functions having same name withy same signature in a single class or in derived class.



Monday, 3 August 2015

Definition of funtction

Function

Function is a separate block of code that is used to reduce complexity
of program.

function is a concept by which we connect two or more than two machine
and two or more than two destination and also transfer data from two or
more than two machine.

Access specifier in c#.net

Types of  access specifier in c#.net

1)Private=private access specifier is a specifier which accessible
 within class.This access specifier is so secure.this is most
commonly used access specifier.

2)protected=Accessible within namespace or assembly.It only occurs
in parent child relationship(inheritance).

3)public=Accessible anywhere.

4)Internal=It is accessible anywhere.By default C# contain
internal access specifier.

5)Partial=It is used to class or interfaces into or more than
two parts.

Saturday, 1 August 2015

coding of customer management system (add and delete)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Customer_management_system
{
    public partial class Form1 : Form
    {
        struct customer
        {
            public int customerID;
            public string firstname;
            public string lastname;
            public DateTime dateofbirth;
        }
        customer[] cus = new customer[1];
        int index = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            cus[index].customerID = Convert.ToInt32(txtcusid.Text);
            cus[index].firstname = txtfirstname.Text;
            cus[index].lastname = txtlastname.Text;
            cus[index].dateofbirth = Convert.ToDateTime(txtdateofbirth.Text);
            index++;
            Array.Resize(ref cus, cus.Length + 1);
            MessageBox.Show("customer added successfuly");
       

        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < index; i++)
            {
                if(cus[i].customerID==Convert.ToInt32(txtcusid.Text))
                {
                    txtfirstname.Text = cus[i].firstname;
                    txtlastname.Text=cus[i].lastname;
                    txtdateofbirth.Text=cus[i].dateofbirth.ToString();
                    return;
                   
                }
            }
            MessageBox.Show("cus id not found");
                   
               
        }
    }
}