Difference between byte vs Byte data types in C#
This question already has an answer here:
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.
上一篇: 字符串与字符串
下一篇: C#中字节与字节数据类型的区别
