Sunday, 29 December 2013

IEnumerator and IEnumerable Interface

IEnumerator and IEnumerable Interface

In simple term collection in C# is a way to store objects. We use System.Collection namespace to work with collection.

IEnumerator and IEnumerable

In collection we are able to access the each element using Enumerator. There is an Interface IEnumerator which contains the following method and properties:-

namespace System.Collections
{
    public interface IEnumerator
    {
    

Thursday, 25 July 2013

Jagged Array in C Sharp

Jagged Array

Jagged array is simply an array of arrays. As we define 2-d array in which each column for each rows are same. But in case of jagged array we can define different column for each rows.

For Example:-

  int[][] jarray =new int[3][];

In this example I declared 2-d array in which rows are 3 but columns are not fixed. We can define column at the runtime for each rows using the following code:-

jarray[0] = new int[3] { 4, 5, 6 };
jarray[1] = new int[2] { 7, 8 };
jarray[2] = new int[4] { 9, 10, 34, 12 };

Sunday, 30 June 2013

Interface in Detail with example of runtime polymorphism

Interface in Detail

Interface in C# is basically a contract in which we declare only signature. The class which implemented this interface will define these signatures. Interface is also a way to achieve runtime polymorphism. We can add method, event, properties and indexers in interface

Syntax of Interface

We declare interface by using the keyword interface which is as follows:-

public interface interface_name
{

    //here we define our signature

}

For Example:-

Create an interface and add some signature of method

public interface Idef1
{
    //singnature of methods

    int sum(int x, int y);
    int mul(int x, int y);

}

Thursday, 20 June 2013

Difference between override and new in C#

Difference between override and new in C#

At the time of overloading we generally use override with virtual. When we need to override the base class method into derived class than we use override keyword.

The difference between override and new is that override extend the method of base class with new definition but new hides the method of base class.

Before understanding the difference between both first we have to understand their use.

Concept of New Keyoword

For Example:-

Create the following base class

public class baseClass
{
    public string ShowHello()
    {

        return "Base Class hello";
   
    }

Tuesday, 29 January 2013

Learn More About Static

For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

More about Static
Let’s have some more detail about static:-
1.       We cannot use this statement with static.
For example:-
See the following example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
    public int x;
    public static int y;

    public void sum(int x, int y)
    {

        this.x = x;
   
    }
}
In this example we create two variable x and y in which y is static variable. We can use non static variable with this but we cannot use static with this.

Operator Overloading in C Sharp


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

Operator Overloading
Before understanding the operator overloading we need to understand why we use operator overloading. In the following example we have one class calculator which contains two variable x and y. and one web form where we create two variables in its cs file and add them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int p = 10;
        int q = 20;
        int r = p + q;
    }
}
 In this operation we didn’t get any problem but if we try to add two objects we will get error like this:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Calculator cal1 = new Calculator();
        cal1.x = 10;
        cal1.y = 20;

        Calculator cal2 = new Calculator();
        cal2.x = 15;
        cal2.y = 25;

        //we will get error that we cannot use + operator of type Calculator(which is ref type)
        Calculator cal = cal1 + cal2;
    }
}

Monday, 28 January 2013

How To Use Delegate and Its Type


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

                                     How To Use Delegate and Its Type

Delegate is a reference type which refer to a method. Delegates object hold the reference of method of same signature. We invoke the method through delegate and this can be determined at the runtime instead of compile time.
Note:-delegates can invoke both static and non static method.

Syntax of delegate:-

Public delegate return_typ delegate_name(parameters);

For Example:-

For non static method
Suppose we are creating a class which contains some method for sum, div, sub and mul of two numbers. We create delegate to hold the reference of these methods.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

Wednesday, 9 May 2012

Can We inherit the interface into another interface?


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

Can We inherit the interface into another interface?



Yes we can inherit the interface into another interface. It follows the same signature for inheritance as we use to inherit the class like:-

1.     Create first interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

Basic of Interface


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

Basic of Interface
Interface is an entity which gives signature or a structure which class have to implement. It contains only declaration not definition. The class which implement the interface will give the definition to each member. It means we can only declare the method, property and event.
Simply interface is ‘what’ should be done and its implementation is ‘how’ it should be done.
Note:-1. All members of the Interface declared without access specifier like public, private etc.
2. We cannot declare any variable in interface.
3. All members should be implemented in the derived class.

Tuesday, 10 April 2012

Access specifier in C#


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

Access specifier in C#
Access specifier defines the accessibility of class member. We can restrict and limit the accessibility of member of classes.
Access Specifier and their accessibility
Access Spicifier
With in class
Derived Class
Outside Class
With in Assembly
Public
Yes
Yes
Yes
Yes
Private
Yes
No
No
No
Protected
Yes
Yes
No
No
Internal
Yes
No
No
Yes
Protected internal
Yes
Yes
No
yes

Above table defines the accessibility of all access spicifier. As this table describe that public member can be accessd everywhere and private accessed only with in class. This create the protection level  that except the class member no other can access the private member of class.

Saturday, 7 April 2012

Basic of Inheritance for beginner


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com


Basic of Inheritance for beginners

Inheritance is property of oops by which we access one class into another class without writing the whole code. The class that is inherited is called base class and the class that does the inheritance is called a derived class.
Note:- two way of accessing class.1. create the object of class. 2. Inherit this class.
Syntax for inheritance
Access-modifier class derived-class: base class
{
}

Thursday, 1 March 2012

Article 5:-How Object is Created?


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

How Object is Created?
Or
Why classes are called Reference Type

As we know that class is a user defined data type.
For creating the object of any class we write the following code:-
Class_Name  Object_Name=new Class_Name();
Suppose the class name is calculator. Then we create the object like that
Calculator cal = new calculator();

Monday, 13 February 2012

Article 4:-Classes in more detail


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

Classes in more detail

Class is the way to realize real time entity in oops. It is the user defined data type. If we want to understand the classes in detail then we need to understand the following topics:--

Ø  Constructor:- for understanding the constructor in detail plz read the following link

Ø  Properties
Ø  Indexers

Sunday, 8 January 2012

Interview question on Constructor


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com


1.      What is constructor?
2.      Can class have more than one static constructor?
3.      Can we create private constructor of a class?
4.      What is the type of the constructor?

Article 3:-Advance Detail of constructor


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com


In the previous article we have learnt the class and constructor in the basic level and in second article we learnt constructor in more detail. Now In this article we will learn advance detail about the constructors
Calling Constructor from another Constructor
Or
Constructor chaining
If you ask the question that can we call constructor from another constructor then I will say yes we can. Calling constructor from another constructor is known as constructor chaining. This can be done by the keyword this and base. Here we discuss on this keyword and will discuss base keyword in the article constructor with inheritance.

Saturday, 7 January 2012

Article 2:-Constructor in more Detail


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com


In the previous article Click here for previous article we have learnt the class and constructor in the basic level. In this article we will learn more about the constructors and will study constructor in detail.

Ques:-1 what is the difference between method and constructors?
Ans:- a) Constructor doesn’t have any return type not even void but every method must contain the return type and if any method doesn’t return anything then it will return void.
b) Constructor called automatically but method is called by the object or with the class name
Note:-in case of static method we call method with the name of class.
c) Constructer will be called only once but we can call the method many times.

Ques 2:-What is the type of constructors?
Ans:- there are two types of constructor and these are following
a)      Static Constructor(also known as class constructor)
b)      Non static Constructor(also known as instance constructor)

Friday, 6 January 2012

Article1:-Concept of Classes and Constructor with Example


For Asp.net Training with C# Click Here

Written By:-Isha Malhotra
Email:-malhotra.isha3388@gmail.com

Ques:-1 What is the Class?
Ans:- Class is the way to realize real time entity in oops. It is the user defined data type.
Syntax of Class
public class Class_Name
Note: public is an access modifier which can be anything like public,private etc.

Ques:-2 What is the Object?
Ans:-Object is the Runtime Entity of the Class.
Syntax of object Creation
Class_Name  object_Name=new Class_Name()

Ques:3 What is Constructor?
Ans:-Constructor is the method inside the class which is used to initialize or give default value to the class member variable. It is invoked when we create new instance of the class.
Features of Constructor
It has same name as the name of the class
It is called automatically when the instance of the class created.
It doesn’t have any return type not even void
Syntax of Constructor