Wednesday, September 26, 2012

Structure of C# Code

using System;
class ClassName
{

 Variable declaration

 Method Declaration

 public static void Main(string []args)
 {

  Create class Object
  Alocate Memory to Object
  Call Functions from the Class

 }
}

Tuesday, September 25, 2012

How to solve a program in C#.Net

First identify the Inputs of the program & also identify the requirements.

 WriteLine() is used for Output
 ReadLine() is used for Input
 Write() is used for Output

ReadLine() Function accept String data from the user


System is a namespace,which helps us to input and output data from user using different classes.

Namespace is a combination of similar type of classes

Ram basic salary is input through keyboard. His HRA is 50% of basic salary and DA is 20 % of basic salary. Calculate the gross salary?

Step 1. Input the basic salary.

Step 2. Identify the basic thinks needed for Program

 Class
 Main
 System
 Console
 WriteLine
 ReadLine


Sample Program:
using System;
class RamSalary
{
 public static void Main(string [] args)
 {
  double sal,HRA,DA,Grossal;

  Console.WriteLine("Enter Salary: ");
  sal = Convert.ToDouble(Console.ReadLine());\\10000
  HRA = sal * .5;\\5000
  DA = sal * .2;\\2000
  Grossal = sal+ HRA + DA;\\17000 = 10000 + 5000 + 2000
  Console .WriteLine("Gross Salary is : {0}",Grossal);
\\17000
 }
}

Saturday, September 22, 2012

Calling asp.net page in IFRAME, from code behind file in C#


Step 1: Write the following code in aspx file:


<IFRAME id="frame1" src="http://www.google.com"  runat="server">
         


Step 2: Write the following code in Code Behind file:

 protected void Button1_Click(object sender, EventArgs e)
{
        frame1.Attributes.Add("src", "
http://www.live.com");
}

Formal Dress Code For Men & Women


Thursday, September 20, 2012

Array using C#.Net 2008

using System;
class Program
{
    static void Main(string[] args)
    {

       //Declaration of Array
       int[] score;

       //initialization of Array 
       score = new int[5];
           

       score[0] = 10;
       score[1] = 20;
       score[2] = 5;
       score[3] = 50;
       score[4] = 40;
       // Displaying an Array  
       for (int j = 0; j < 5; j++)
       {
           Console.WriteLine(score[j]);
       }
      

       //For Each Loop
       foreach (int k in score)
       {
           Console.WriteLine(k);
       }
       Console.ReadLine();
    }
}

While Loop & Do While Loop in C#.Net 2008

using System;
class Program
{
    static void Main(string[] args)
    {
       //While LOOP           

       int i;
       i = 0;
       while (i <= 10)
       {
           Console.WriteLine("While Loop");
           i++;
       }
      

       //Do While LOOP
       int j;
       j = 0;
       do
       {
          Console.WriteLine("do While Loop");
          j++;
       } while (j <= 10);
   

       Console.ReadLine();
   }
}

How to write a Simple For Loop in C#.Net 2008

using System;
class Program
{
    static void Main(string[] args)
    {
       for (int i = 0; i <= 10; i++)
       {
           Console.WriteLine("Hello");
       }
       Console.ReadLine();
    }
}

How to write a simple switch case in C#.Net 2008

using System;
class Program
{
  static void Main(string[] args)
  {
    int i;

    i = 0;
    Console.WriteLine("Enter any number: ");
    i = Convert.ToInt32(Console.ReadLine());
    switch (i)
    {
      case 1:
              Console.WriteLine("One");
              break;
      case 2:
              Console.WriteLine("TWO");
              break;
      case 3:
              Console.WriteLine("Three");
              break;
      default:
         Console.WriteLine("invalid Number");
         break;
    }
    Console.ReadLine();
  }
}

How to write Simple Program in C #.Net 2008

using System;
class Program
{
     static void Main(string[] args)
     {
          Console.WriteLine("Hello");
          Console.ReadLine();
     }

}