Statements
Program instruction is called a statement and each statement ends with a semicolon (;). The compiler starts at the beginning of a source code file and reads down, executing statement after statement in the order encountered. This would be entirely straightforward, and terribly limiting, were it not for branching . Branching allows you to change the order in which statements are evaluated. Examples :
int newvariable;
newvariable = 23;
int oldvariable = newvariable;
Types
Every object you create or use in a C# program must have a specific type (e.g., you must declare the object to be an integer or a string or a Dog or a Button).
Variables
A variable is an instance of an intrinsic type (such as int). You can initialize a variable by writing its type, its identifier, and then assigning a value to that variable. An identifier is just an arbitrary name you assign to a variable, method, class, or other element. Examples for using variable:
class Values
{
static void Main( )
{
int mycount = 7;
System.Console.WriteLine("First value, mycount: {0}",mycount);
mycount = 5;
System.Console.WriteLine("Second value, mycount: {0}",mycount);
}
}
Constants
A constant is like a variable in that it can store a value. However, unlike a variable, you cannot change the value of a constant while the program runs. Example constants :
class Values
{
static void Main( )
{
const int FreezingPoint = 32; // degrees Fahrenheit
const int BoilingPoint = 212;
System.Console.WriteLine("Freezing point of water: {0}",
FreezingPoint );
System.Console.WriteLine("Boiling point of water: {0}",
BoilingPoint );
//BoilingPoint = 21;
}
}
No comments:
Post a Comment