Welcome To Shadab's Blog

Programming Blog to learn C# , java, Sql Server 2005 and many more things.





About Me

My photo
Bokaro, Jharkhand, India

Monday, December 13, 2010

How to call a method through Object?

We hava learnt that what is object ?
Now it is important to note that we can call non-static method through object in C#.

Non-Static Method: Those method which is declare without static keyword are called non-static method.

For Ex :-  public void Add() //here Add is a non static method
               {
                          //method body
                 }

now see this example in which see how can we call non static method through object.

using System;
class Call
{
          public void Add()         //non static method
          {
                  Console.WriteLine("This is Add method");
           }
           public static void Main()
          {
                   Call obj=new Call(); //obj is object of Call class
                   obj.Add();                   //calling Add() method through ob
           }
}

//output will be
This is Add method

Tuesday, November 30, 2010

Program To Implement Matrix Multiplication in C#

using System;

class abc
{
public static void Main()
{

int [,]matrix1=new int[3,3]

{{4,5,7},
{2,4,6},
{1,5,7},
};

int [,]matrix2=new int[3,3]
{
{2,5,1},
{1,2,4},
{3,5,7},
};
int [,]matrix3=new int[3,3];

for(int row=0;row<=2;row++)
{
for(int col=0;col<=2;col++)
{
matrix3[row,col]=matrix1[row,0]*matrix2[0,col]+matrix1[row,1]*matrix2[1,col]+matrix1[row,2]*matrix2[2,col];
}
}
Console.WriteLine(" Resultant Matrix is ");
for(int row=0;row<=2;row++)
{for(int col=0;col<=2;col++)
{
Console.Write(matrix3[row,col]+" ,");
}
Console.WriteLine("\n");
}
}

Thursday, November 25, 2010

How to create object in C# programming ?

First of all I want to say sorry to all bcoz I m writting this blog after a long time.

Today I want write how to create object(instance) in programming language.
In last post i have written what is object?

For creating object we have to write  following line of code

   classname objectname=new classname(); 

After writting this code we can call method or access variable of that class
here classname refers name of class .
and object name refers name of object.
new is a key word that allocates memory for the object.

to clear understand see following code below.

class ABC
{
          public static void Main()
         {
                 ABC obj=new ABC(); //here obj is actual object.
          }
}

To call a method in  C# and how to access variable in C# we will learn next day.

Thursday, June 10, 2010

Friday, March 12, 2010

What is mthod in programming language OR in C# programming language ?

As discuss in previous post that behavior and method are same thing.
                       Now I am going to give a definition of method in programmatically.
Method-> In programming languages set of statementthat is written inside a block {} and used to perform a specific task is callled method.

In other words any task that is performed by object is called method or behaviour of an object .
Suppose you have ability to talk ,write,and move read all these are your behavior.

Now how to write a method in programing language ?
Syntax-

Access-spcifire retrun-type MethodName()
{
            //Set of statement that has a spedific task..
}

Now a short Example ->
public void Add() //this is an Add method
{
     res=num1+num2 //instruction that is written here
}

Friday, January 22, 2010

What is an Object?

Now you have learnt what a class is in programming language.

Actually above definition was in general term.
But we can define it in programming language like:


CLASS- > Set of attribute (variable) or behavior (method) that is shared by all the object of a particular type is called class. It is a blue print for creating the object.

Now I’ll discuss the object.

What is an Object?

In Real life we see many things we can say all are object.
Like TV, computer, dog, ram (name of a boy), CPU, keyboard etc all are object.
I n programming language an object is an entity mean that has existence.

Whether it logical or physical.
Logical means we can’t touch it. Like XP operating system, Vista.
Physical means we can touch it. Like dog, cat, computer, TV etc.






In other words object is an instance of a class.


Suppose you are an object and your name is Ram.
Then Ram would be an object of human_beings class.


We can identify an object very easily.






Object has thee characteristics by which we can easily identify it.
1. State->set of attribute and their values is called state.
                      Suppose car is an object of a Automobile class.
                      Then every car has some state like
                       Speed=0, color=”red”, no_of_wheel=4 etc.


                      For example -> you are an object that means you have a state.
                      What is your set of attribute?


                     Your height, weight, no_of_hands, complexion etc.
                      And if put some value to your attribute that is called your state.






2. Identity->Identity is one of the most important characteristics of Object by which
                            we can easily   identify an object.
                            Suppose you are an object then what is identification marks?
                            Your finger print is identification marks.
                            Suppose a computer is an object then its model number is its identification marks.






3. Behavior-> in general term any task that is performed by an object is called Behavior. In programming language it is called method as well.
                                For example -> suppose you are an object what would be your behavior.
                                You can speak, you can walk, you can talk, you can write.
                                Above discussed verb like walk, move, talk, write
                               all these are your method or we can say behavior.




                             Now it seems to me that you can understand that
             What an object is in programming language?




















Tuesday, January 19, 2010

Some Basic Concept in C# programming.

Today i'll write a topic in C# programming that would clear your concept regarding some basic terms like
1.class
2.object
3.Methods



->Some Basic point in C#
1.what is a class in programming language?
                we see many things in real life for example computer,cow,lion,mixer,cd player,mouse,ram(a humanbeings or name of a man),printer,tree and etc.you know it is an object.i'll discuss it later.
                 first we categorized it according to their behaviour and some properties into a group this logical group makes a class.
suppose we categorize cow,lion,Goat into one group that makes a class and we can say Animal .
That means Animal is a class where each animal belongs.
And According to my defination some properties of cow like four foots,two ears and one mouth each has those things that'why we categorized into animal ..now we can eaisly catrgorized other things like cd player,Tv into electornics device and we can give a name it "ELECTRONICS DEVICE " that is a class.

 A simple class is declared in C# like
class Animal
{
           
}
wherer class is keyword(keywords are the word that has special meaning in programming  language )
and Animal is name  of class..
Now I'll disscuss about object next day.