字节之间的差值Vs在C#中的字节数据类型 [英] Difference between byte vs Byte data types in C#
问题描述
我注意到,在C#中有既有的字节和字节的数据类型。他们都表示,他们的类型均为结构System.Byte 并代表一个8位无符号整数。
I noticed that in C# there are both a byte and Byte data type. They both say they are of type struct System.Byte and represent an 8-digit unsigned integer.
所以我很好奇,如果任何区别在于两者之间什么,以及为什么你会使用一个比其他。
So I am curious as to what the difference if any is between the two, and why you would use one over the other.
谢谢!
推荐答案
的字节
关键字的别名 System.Byte
数据类型。
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:
-
您可以使用
字节
即使不包括系统
命名空间。要使用字节
你必须有一个使用系统;在页面顶部
,或指定完整的命名空间System.Byte
。
You can use
byte
even if theSystem
namespace is not included. To useByte
you have to have ausing System;
at the top of the page, or specify the full namespaceSystem.Byte
.
有一些情况下C#只允许您使用关键字,而不是框架类型,例如:
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
}
这篇关于字节之间的差值Vs在C#中的字节数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!