using System;
using System.Collections.Generic;
using System.Text;
namespace HelloWorld
{
struct Fraction1
{
public int numerator;
public int denominator;
}
class Fraction
{
public int numerator;
public int denominator;
}
class Program
{
static void Main(string[] args)
{
//testHelloWorld();
//testBasicType();
//testClass();
//testCAL();
//testif();
//testifelse();
//testStruct();
//testswitch();
//testfor();
/*学习总结
* 简单数据类型
* 值和引用
* 常量与变量
* 表达示和运算符
* 条件语句 if ..else /switch...c
* 循环语句while/do..while/for
* 跳转语句break/continue
* 错误和异常处理
*/
}
private static void testWhile()
{
int i = 0;
int sum = 0;
while (i < 10)
{
i++;
sum += i;
}
Console.WriteLine("{0}", sum);
}
private static void testWhiledo()
{
int i = 0;
int sum = 0;
do
{
i++;
sum += i;
} while (i < 10);
Console.WriteLine("{0}", sum);
}
private static void testfor()
{
int sum = 0;
for (int i = 0; i < 10;i++)
{
sum +=i;
}
Console.WriteLine("{0}", sum);
}
private static void testHelloWorld()
{
System.Console.WriteLine("Hello,World!");
}
private static void testStruct()
{
Fraction1 h;
h.numerator = 3;//define struct
h.denominator = 3;
Console.WriteLine("h = {0}/{1}", h.numerator, h.denominator);
}
private static void testClass()
{
Fraction h = new Fraction();
h.numerator = 3;
h.denominator = 5;
Console.WriteLine("h = {0}/{1}", h.numerator, h.denominator);
}
private static void testCAL()
{
const Char i = 'b';
Console.WriteLine("i = {0}", i);
Console.WriteLine("true && false:{0}", true && false);
Console.WriteLine("true || false:{0}", true || false);
int j = 0x000f0005, k = 0x00f0f003;
Console.WriteLine("j = 0x{0:x8},k = 0x{0:x8}", j, k);
Console.WriteLine("j = 0x{0:x8},k = 0x{0:x8}", ~j, ~k);
Console.WriteLine("j&k = 0x{0:x8}", j & k);
Console.WriteLine("j|k = 0x{0:x8}", j | k);
Console.WriteLine("j^k = 0x{0:x8}", j ^ k);
Console.WriteLine("17+5={0}/r/n17-5={1}/r/n17*5={2}/r/n17/5={3}/r/n17%5={4}", 17 + 5, 17 - 5, 17 * 5, 17 / 5, 17 % 5);
Console.WriteLine("17 > 5={0}/r/n17>=5={1}/r/n17<5={2}/r/n17<=5={3}/r/n17==5={4}/r/n17!=5={5}", 17 > 5, 17 >= 5, 17 < 5, 17 <= 5, 17 == 5, 17 != 5);
Console.WriteLine("2<<2={0}", 2 << 1);
}
private static void testBasicType()
{
short x = 32766;
ushort y = 65534;
Console.WriteLine("x = {0}", x);
Console.WriteLine("y = {0}", y);
x++;
y++;
Console.WriteLine("x = {0}", x);
Console.WriteLine("y = {0}", y);
x++;
y++;
Console.WriteLine("x = {0}", x);
Console.WriteLine("y = {0}", y);
bool a = true;
bool b = false;
Console.WriteLine("a = {0}", a);
Console.WriteLine("b = {0}", b);
float c = 3.1415926f;
double d = 3.141519253579;
Console.WriteLine("c = {0}", c);
Console.WriteLine("d = {0}", d);
c = (float)d;
Console.WriteLine("c = {0}", c);
decimal e = 1.23567894566m;
e *= 2;
Console.WriteLine("e = {0}", e);
char f = '我';
char g = 'A';
Console.WriteLine("f = {0}", f);
Console.WriteLine("g = {0}", g);
}
private static void testif()
{
if (2 > 1)
{
Console.WriteLine("2>1");
}
}
private static void testswitch()
{
string fruit;
//strng sTemp;
//sTemp = Console.ReadLine;
//iMark = Int32.Parse(sTemp);
fruit = "apple";
switch (fruit)
{
case "apple":
Console.WriteLine("I am an apple");
break;
case "pineapple":
Console.WriteLine("I am a pineapple");
break;
case "strawberry":
Console.WriteLine("I am a strawberry");
break;
default:
Console.WriteLine("I am nothing");
break;
}
}
private static void testifelse()
{
int iMark;
//strng sTemp;
//sTemp = Console.ReadLine;
//iMark = Int32.Parse(sTemp);
iMark = 100;
if (iMark == 100)
{
Console.WriteLine("full");
}
else if (iMark >= 85)
{
Console.WriteLine("good");
}
else
{
Console.WriteLine("bad");
}
}
}
}