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

Saturday, January 16, 2010

DATA TYPES IN C#

DATA TYPES IN C# :
                       First of all we have to understand that what is a data type ?
Data types specifies that which type of value will be contained by a
variable either integer or character or etc.
some data types is given below.

  1. int
  2. string
  3. char
  4. bool
  5. float
  6. double
  7. byte
  8. long
  9. short
and etc.
in next blog i'll discuss how to accept and display the different data types in screen

Step By Step C# program

Today I am going to write a Blog in which I will writer how to learn C# programming.


I will give you simple and easy way idea by which you can easily write a program.



Here you can ask any question in C#.



Now I am going to write step by step C# ’s program.





using System;

class First

{

public static void Main()

{

Conosle.WriteLine("Welcome to C# programming");

}

}

Monday, December 21, 2009

A simple Even and Odd Program in C#.

using System;
class  ODD_Even
{
             public static void Main()
             {
                    Console.WriteLine("Enter a number ");
                     int num=Convert.ToInt32(Console.ReadLine());
                     
                     if(num%2==0)
                    {
                            Console.WriteLine("number is even");
                    }
                   else
                    {
                          Console.WriteLine("Number is Odd");
                       }

              }
}

Saturday, December 19, 2009

How to pass Arrary as Parameter

you can pass array as parameter by using params keyword in C#.
Following program is shown how to pass array as parameter

using System;

class Array_parameter
{
public void display(int num,params int [] arr1)
{
Console.WriteLine("Num ="+num);
Console.WriteLine("Array's values are ");
foreach(int i in arr1)
{
Console.WriteLine(i);
}
}
public static void Main ()
{
Array_parameter obj=new Array_parameter();
obj.display(44,12,2,25,45,85);
}
}

/*here when display method is called then some argument is send

together first argument inserted into varible num in display method

and rest element are goes into reference of arr1

out will be--
Num=44
Array's values are
12
2
25
45
85

Example of out parameter in C#

using System;
class out_demo
{
public void add(out int num)
{
num=90; //set the value in reference of num
}
public static void Main()
{
int num; //local variable but not initialized
out_demo obj=new out_demo();
obj.add(out num);
Console.WriteLine(num);
}
}

//output will be
//90
//now we can say that in case of out parameter value transfered out from the method named add()

Friday, December 18, 2009

What is delegate in C# ?Explain with program.

using System;

class Delegate_Demo
{
public delegate void mydel(); //delegate declaration named mydel

public void method1()
{
Console.WriteLine("Method1");
}

public void method2()
{
Console.WriteLine("Method2");
}

public static void Main()

{

Delegate_Demo d=new Delegate_Demo();

mydel m1=new mydel(d.method1); //m1 contain's only one reference i.e method1

m1();

mydel m2=new mydel(d.method1);

m2+=new mydel(d.method2); //assinging multiple reference

m2(); //m2 contains two reference i.e method1 and method2

}

}

/*output will be
Method1
Method1
Method2

*/

A simple Program in C#

class First
{
           public static void Main()
           {
                  System.Console.WriteLine("Welcome to C# programming");
           }
}

// you can save this file as extenstion .cs and then compile it...
For compilng -> open commnd prompt
write -> csc filename.cs press enter

For Run-> write only filename on command prompt