10/02/2010 (wed)
switch
int i=2
switch(i)
{
case 1:
case 2: Console.WriteLine("Hello");
break;
}
If case1 uses without break and no statement sequence, it will work.
for()
for(); = for() {}
*Using ";" after for, it means sentence end.
for(int i=10,j=12; i<0; i++,j--) {}
increment operator
pre increment ++i = i+1
post increment i++ = i+1
Both are same meaning, but increment timing is different.
ex1
int i=5;
int j=i++ +6;
Result 11
ex2
int i=5;
int j=++i +6;
Result 12
ex3
int i=5;
int j=++i - --i + i++;
Console.WriteLine(i);
Console.WriteLIne(j);
Result 6(i)
6(j)
ex4
int i=10;
int j=5;
int k=i-- - --i * --j + j++ / i++;
Console.WriteLine(i);
Console.WriteLine(j);
Console.WriteLine(k);
Result
9(i)
5(j)
-22(k)
k=10-8*4+4/8
=10-32+0
=-22
for : We know how many times it works for loop.
while : We don't know how many times it works for loop.
do while : At least one time.
whille(bool condition)
{
Console.WriteLine(" ");
}
do
{
Console.WriteLine(" ");
} while(bool condition);
string value=Console.Readline();
It means to read someone to input value.
int i=int.Parse(value);
It means to cast from string to integer.
Lotto example
Console.WriteLine("Enter number between 1 and 100");
string number = Console.ReadLine();
int num = int.Parse(number);
while (num != 50)
{
Console.WriteLine("Sorry you missed chance");
Console.WriteLine("Please enter 1 if you want play again otherwise enter 0");
string choice = Console.ReadLine();
int value = int.Parse(choice);
if (value == 0)
{
Console.WriteLine("Good bye");
break;
}
else
{
Console.WriteLine("Enter any number between 1 and 100");
string number1 = Console.ReadLine();
int num1 = int.Parse(number1);
if (num1 == 50)
{
Console.WriteLine("congratulation you won prises of 200,000 dollar");
break;
}
}
}
if (num == 50)
{
Console.WriteLine("congratulation you won prises of 200,000 dollar");
}
0 件のコメント:
コメントを投稿