Difference between byte vs Byte data types in C#

This question already has an answer here:

  • What is the difference between String and string in C#? 59 answers

  • The byte keyword is an alias for the System.Byte data type.

    They represent the same data type, so the resulting code is identical. There are only some differences in usage:

  • You can use byte even if the System namespace is not included. To use Byte you have to have a using System; at the top of the page, or specify the full namespace System.Byte .

  • There are a few situations where C# only allows you to use the keyword, not the framework type, for example:

  • .

    enum Fruits : byte // this works
    {
      Apple, Orange
    }
    
    enum Fruits : Byte // this doesn't work
    {
      Apple, Orange
    }
    

    byte and System.Byte in C# are identical. byte is simply syntactic sugar, and is recommended by StyleCop (for style guidelines).


    C# has a number of aliases for the .NET types. byte is an alias for Byte just as string is an alias for String and int is an alias for Int32 . Ie byte and Byte are the same actual type.

    链接地址: http://www.djcxy.com/p/3588.html

    上一篇: 字符串与字符串

    下一篇: C#中字节与字节数据类型的区别