Variable Declaration

A variable is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value. The variable name is the usual way to reference the stored value

How to declare variables

Syntax: - Data type variable name [=initializing value];
Ex: int a;
       string s;
       double x;
       int a, b, c;

print Variable Data on the Screen
  • To print variable data on the screen there are 2 methods available
  •  If we have int a=10;
  • We use Console.WriteLine(“Value of a is:-“ +a);
  • In the above statement + is known as concatenate operator
  • We can also use Console.WriteLine(“Value of a is :- {0}”,a);
  •  In the above statement {0} is known as Output stream argument
Reading the Data from the User

To Read the data from the user there are 2 methods available
1)    ReadLine(  )
2)    Read(  )

Syntax of ReadLine( ) / Read( )
Variable name = Console.ReadLine(  );
Variable name = Console.Read( );


Steps to add a new class file:-
  1. Go to Solution Explorer
  2. Select the solution click with Right mouse button
  3.  Click on New Item
  4. Select Class template
  5. Type the class name (ClsExample2.cs)
  6.   Click on Add

Steps:-
1]
  2]

 Example with Console.Write( ),Console.WriteLine( ) Methods

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CABasics
{
    class ClsExample2
    {
        static void Main()
        {
            int a = 10;
            Console.WriteLine("Value of a is"  +a);
            Console.WriteLine("Value of a is {0}", a);
            Console.Read();

        }
    }
}


                  
Output:-

Before Running the above program change the startup object


Steps to change startup object


Go to solution explorer                      

Double click on properties   

Go to startup object

Select the class file name to execute

Save and close the properties window



 Steps:-



 1]

 2]


 

 

No comments:

Post a Comment