Professional Documents
Culture Documents
Lec 2
Lec 2
PROGRAMING
Next Topic
Array
Loops
String concatenation
Case Sensitives
Casting ( Conversion )
* Scopes
FUNDAMENTALS OF
PROGRAMING
Arrays are used to store multiple values in a single variable, instead of declaring separate
variables for each value.
To declare an array, define the variable type with square brackets []
Arrays are used to store multiple values in a single variable, instead of declaring separate
variables for each value. To declare an array, define the variable
// declare an array
int[] age;
string[] cars;
string[] cars = {“mehran", “alto", “Toyota", “city"};
Console.WriteLine(cars[0]);
FUNDAMENTALS OF
PROGRAMING
// Create an array of four elements, and add values later
string[] cars = new string[4];
Loops
1.For
2.Foreach
3.While
4.Do While
FUNDAMENTALS OF
PROGRAMING
for (initialization; condition; iterator)
{
// body of for loop
}
String concatenation
String functions
Generally, smaller types like int (having less memory size) are automatically converted to larger types like double
(having larger memory size).
Generally, larger types like double (having large memory size) are converted to smaller types like int (having small
memory size).
double numDouble = 1.23;
// Explicit casting
int numInt = (int) numDouble;
double x = 1234.7;
int a;
// Cast double to int.
a = (int)x;
FUNDAMENTALS OF
PROGRAMING
Generally, while performing type conversion between non-compatible types like int and string, we use Parse().
string n = "100";
// converting string to int type
int a = int.Parse(n);
Generally, while performing type conversion between non-compatible types like int and string, we use Parse().
Case Sensitives
int Count = 1;
string[] flower = { "pink”,”yellow”,”red”,”green" };
//for (int count = 0; count <flower.Length; count++)
for (int count = 0; count <flower.Length; count++)
{
Console.WriteLine(flower[Count]);
}
FUNDAMENTALS OF
PROGRAMING
IF else Condition
WHAT'S APP NUMBER
WHAT'S APP :92-3193416769
EMAIL:12SOLUTIONSSS@GMAIL.COM