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
Syntax: - Data type variable name [=initializing value];
print
Variable Data on the Screen
Syntax of ReadLine( ) / Read( )
Example with Console.Write( ),Console.WriteLine( ) Methods
Before Running the above program change the startup object
How to declare variables
Syntax: - Data type variable name [=initializing value];
Ex: int a;
string s;
double x;
int a, b, c;
- 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:-
- Go to Solution Explorer
- Select the solution click with Right mouse button
- Click on New Item
- Select Class template
- Type the class name (ClsExample2.cs)
- Click on Add
Steps:-
1]
2]
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