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

Thursday, December 17, 2009

Welcome To MyBlog

Hi , I am shadab ..This is my first Blog.Through this Blog I want to help all the person who wants to learn programming .Any type of help in logical question in any programming language such as C++,C# and java will be given by this blog . I hope all student who wants help from me can read my blog regularly.
                      I will post many logical as well as coceptual question's answer in this blog .
The student who wants access this blog can write in URL
http://www.shadab-programminghelp.blogspot.com/