//using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TextHello
{
class Program
{
// Hellow world program
static void Main(string[] args)
{
System.Console.WriteLine("Hello World");
int x = 10;
int y = 3;
int result = x % y;
System.Console.WriteLine("result =" + result);
System.Console.WriteLine("{0} + {1} = {2}", x, y, (x + y));
System.Console.ReadLine();
// for loop
for (int i = 10; i >= 0; i--)
{
System.Console.WriteLine("i=" + i);
}
// while loop
int ix = 10;
while (ix >= 0)
{
System.Console.WriteLine("ix =" + ix);
ix--; // ix = ix-1;
}
// do while loop
// executes at least one line
int iy = 10;
do
{
System.Console.WriteLine("iy =" + iy);
iy--;
} while (iy > 0);
// and or statemnet
// short and && or || vs. regular and & or |
// shorts ones don't check the second arg once the first arg is satisfied.
// regular ones always checks every arg in bracket
System.Console.WriteLine("-------------- and or statement && ||");
x = -10;
y = 10;
if (x >= 0 && y >= 0)
{
System.Console.WriteLine("both numbers positive");
}
else if (x >= 0 || y >= 0)
{
System.Console.WriteLine("at least one number positive");
}
else
{
System.Console.WriteLine("both numbers negative");
}
// switch case
System.Console.WriteLine("----------- switch case");
string j = "Two";
switch (j)
{
case "Zero":
System.Console.WriteLine("value is 0");
break;
case "One":
System.Console.WriteLine("value is 1");
break;
case "Two":
System.Console.WriteLine("value is 2");
break;
case "Three":
System.Console.WriteLine("value is 3");
break;
default:
System.Console.WriteLine("value not found");
break;
}
//
// declare array
//
System.Console.WriteLine("--------------- array manipulation");
int[] a = { 10, 20, 30, 40, 50, 60};
System.Console.WriteLine(a[3]);
a[4] = 55;
System.Console.WriteLine(a[4]);
for (int i = 0; i < a.Length; i++ )
{
System.Console.WriteLine("a["+i+"] ="+ a[i]);
}
foreach (int tempvar in a)
{
System.Console.WriteLine(tempvar);
}
// initialize array and then assign values
System.Console.WriteLine("---------- assign array values");
int[] xx = new int[6];
xx[0] = 10;
xx[3] = 50;
foreach (int z in xx)
{
System.Console.WriteLine(z);
}
// manipulate text
System.Console.WriteLine("----------- manipulate text");
string c = "David Beckham";
System.Console.WriteLine("Hello " + c);
System.Console.WriteLine(c.ToUpper()); // DAVID BECKHAM
System.Console.WriteLine(c.Substring(2));//vid Beckham
System.Console.WriteLine(c.Substring(4,5));//d Bec
System.Console.WriteLine(c.IndexOf("v"));//2
System.Console.WriteLine(c[1]);//a
// text array
string[] cy = {"one", "two", "three" };
foreach (string z in cy)
{
System.Console.WriteLine(z);
}
// change text to number
System.Console.WriteLine("-------- change text to number");
string age = "34";
string sal = "8743784.71";
int g = System.Convert.ToInt32(age);
System.Console.WriteLine("g/2= " + g/2);
System.Console.WriteLine("sal*0.02= " + System.Convert.ToDouble(sal)* .02);
// End of program
System.Console.ReadLine();
}
}
}