字节之间的差值Vs在C#中的字节数据类型 [英] Difference between byte vs Byte data types in C#

查看:175
本文介绍了字节之间的差值Vs在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 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.

有一些情况下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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆