码迷,mamicode.com
首页 > Windows程序 > 详细

C#笔记1__

时间:2014-12-23 21:03:43      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

命名空间: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();
        }
    }
}

 

C#笔记1__

标签:

原文地址:http://www.cnblogs.com/fish7/p/4181165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!