您的位置:首页 > 移动开发 > Objective-C

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

2014-12-23 20:43 435 查看
命名空间: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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: