111,125
社区成员
发帖
与我相关
我的任务
分享class Demo
{
static void Main()
{
Console.WriteLine("☆☆☆");
}
}
/*
Microsoft (R) Visual C# 2005 编译器 版本 8.00.50727.1433
用于 Microsoft (R) Windows (R) 2005 Framework 版本 2.0.50727
版权所有 (C) Microsoft Corporation 2001-2005。保留所有权利。
Demo.cs(5,5): error CS0103: 当前上下文中不存在名称“Console”
*/namespace Demo.System
{
struct Int32{} // 即使去掉此行,下面的 System.Int32 的含义和 int 仍然不一样。
class Program
{
static void Main()
{
System.Int32 i; // 此处 System.Int32 的含义和 int 不一样。
global::System.Console.WriteLine(i);
}
}
}// 另外,int 是 C# 的关键字,而 System.Int32 不是,所以在 @ 后面的表现不一样。
class Program
{
static void Main()
{
@System.Int32 i = 5; // 没问题
@int j = 5; // error CS0246: 找不到类型或命名空间名称“int”
}
}using System;
class Program
{
static void Main()
{
// typeof(int) 和 typeof(System.Int32) 是一样的,都是 System.Int32。
Console.WriteLine(typeof(int)); // 输出: System.Int32
Console.WriteLine(typeof(System.Int32)); // 输出: System.Int32
Console.WriteLine(typeof(int) == typeof(System.Int32)); // 输出: True
// 但 Type.GetType("int") 和 Type.GetType("System.Int32") 不一样,
// 前者为 null,后者是 System.Int32。
Console.WriteLine(Type.GetType("int")); // 输出: 空
Console.WriteLine(Type.GetType("System.Int32")); // 输出: System.Int32
Console.WriteLine(Type.GetType("int") == Type.GetType("System.Int32")); // 输出: False
Console.WriteLine(typeof(int) == Type.GetType("System.Int32")); // 输出: True
Console.WriteLine(typeof(int) == Type.GetType("int")); // 输出: False
}
}