关键字是为了方便大家使用,而特意为.net拿出来直接使用的类型,如int,short,long,string,delegate及enum等类型都是关键字,现在说一下它们的原型(F2键,转到定义可以看到)

 

int  => public struct Int32
short => public struct Int16
long => public struct Int64
string => public sealed class String
enum => public abstract class Enum
delegate =>  public abstract class Delegate 
 
当我们使用int时,Int32结构体里的常量,属性,方法我们都可以使用,这是为什么呢,这是因为int是int32的一个别名,我们在C#里可以使用using int=Int32来实现,但注意本语句必须放在名称空间里的第一行才可以。
例如:
namespace ConsoleApplication1
{
    using zzl = Zzl;
 
    class Program
    {
        static void Main(string[] args)
        {
            zzl.Hello();
            
        }
    }
 
    class Zzl
    {
        public static void Hello()
        {
            Console.WriteLine("Hello My Item");
        }
 
    }
}

相关文章:

  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2021-10-08
  • 2021-08-02
  • 2022-12-23
  • 2021-06-12
  • 2021-11-20
  • 2022-12-23
  • 2021-05-19
相关资源
相似解决方案