Problem
In C#, I realized that there is a byte and a Byte data type. They both claim to be of the struct System type. An 8-digit unsigned integer is represented by a byte.
So, what is the difference, if any, between the two, and why would you choose one over the other?
Thanks!
Asked by jaywon
Solution #1
The byte keyword is a System alias. The data type byte is used to describe the size of a byte.
Because they represent the same data type, the code generated is similar. There are only a few distinctions in usage:
.
enum Fruits : byte // this works
{
Apple, Orange
}
enum Fruits : Byte // this doesn't work
{
Apple, Orange
}
Please see the link for a complete list of aliases.
Answered by Guffa
Solution #2
byte and System are two terms that are used interchangeably. In C#, byte and byte are the same thing. StyleCop recommends the use of byte as a syntactic sweetener (for style guidelines).
Answered by Adam Maras
Solution #3
There’s no difference. System is an alias for byte. In the same manner that int is an alias for System, Byte is an alias for Byte. To System, int32, long To System, int64, string a string…
Answered by Darin Dimitrov
Solution #4
The.NET types have a number of aliases in C#. In the same way that string is an alias for String and int is an alias for Int32, byte is an alias for Byte. In other words, the real types byte and byte are the same.
Answered by Brian Rasmussen
Solution #5
The lowercase one is a keyword that serves as an alias for the Byte type.
This is syntactic sugar in its purest form.
Answered by Gerrie Schenck
Post is based on https://stackoverflow.com/questions/2415742/difference-between-byte-vs-byte-data-types-in-c-sharp