C#学习(2天)

主要学习内容:
一、变量:
sbyte:-128-127
byte:0-255
short:-32768--32767
ushort:0-65535
int:
uint:
long
ulong
bool:true,false
string:
char:
decimal:
float:
语言的变量都大同小异,与其它语方相对多了个byte\sbyte,其它都差不多
二、命名空间。namespace,只知道其用法,但不太明白为啥还要命名空间这个概念?
三、位运算符:与、或、非、位移,二进制就学过的东西。
四、GOTO语句问题,
五、三元运算符:<test>?<resultiftrue>:<resultiffalse>,跟PB一样
     if(<test>)
      <code executed if <test> is true>;
    else
     <code executed if <test> is false>;
示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string comparison;
            Console.WriteLine("Enter a number");
            double var1 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Enter another number");
            double var2 = Convert.ToDouble(Console.ReadLine());

            if (var1 < var2)
                comparison = "Less than";
            else
            {
                if (var1 == var2)
                    comparison = "equal to";
                else
                    comparison = "greater than";

            }

            Console.WriteLine("The first number is {0} the second number.", comparison);
            Console.ReadKey();
        }
    }
}


switch语句示例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            const string myName = "karli";
            const string sexyName = "angelina";
            const string sillyName = "ploppy";

            string name;
            Console.WriteLine("what is your name?");
            name = Console.ReadLine();

            switch (name.ToLower())  //Tolower()小写转换
            {
                case myName:
                   Console.WriteLine("You have the same name as me !");
                    break;
                case sexyName:
                    Console.WriteLine("My,what a sexy name you have");
                    break;
                case sillyName:
                    Console.WriteLine("That's a very silly name.");
                    break;

            }

            Console.WriteLine("Hello {0}", name);
            Console.ReadKey();
        }
    }
}



posted @ 2009-09-20 21:18  zxlxy  阅读(207)  评论(0)    收藏  举报