C#笔记1__命名空间 / 常量 / object / is、as、...?... :...

命名空间:namespace Test1{ ... }    

引用命名空间:using System;

using 别名=命名空间

 

常量:const double PI=3.14;

 

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

namespace Test1{
    class Program{
        static void Main(string[] args){
            object ob;
            ob = 10;
            Console.WriteLine(ob.GetType());
            ob = true;
            Console.WriteLine(ob.GetType());
            ob = 10.13m;
            Console.WriteLine(ob.GetType());

            Console.ReadLine();
        }
    }
}

 

namespace Test1{
    class Program{
        static void Main(string[] args){
            int a = 10;
            if (a is bool) //表达式 is 类型 
                Console.WriteLine("yes");
            else
                Console.WriteLine("no");

            object[] nums = new object[3];
            nums[0] = 123;
            nums[1] = "hell";
            nums[2] = "字符串";
            for (int i = 0; i < nums.Length; ++i) {
                //表达式 as 引用类型       当as指定的转换不能实现时,运算结果为null
                string s = nums[i] as string; //将数组nums的对应元素转换成字符串
                Console.WriteLine("nums[{0}]", i);
                if (s != null) {
                    Console.WriteLine("not a null");
                } else {
                    Console.WriteLine("is a null");
                }
            }
            bool k1 = 5 > 3 ? true : false;
            Console.WriteLine(k1);
            

            Console.ReadLine();
        }
    }
}

 

posted @ 2014-12-23 20:43  fish7  阅读(338)  评论(0编辑  收藏  举报