Showing posts with label Tech Altum Training Centre. Show all posts
Showing posts with label Tech Altum Training Centre. Show all posts

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

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;