Difference between bytes and byte data types in C #

I noticed that in C # there is a data type byte and Byte . They both say they are of type struct System.Byte and are an 8-digit unsigned integer.

So I'm curious what difference, if any, exists between the two, and why you will use one over the other.

Thank!

+81
c # byte
Mar 10 '10 at 9:28
source share
8 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 use:

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

  • There are several situations where C # allows you to use a keyword rather than a frame type, for example:

.

 enum Fruits : byte // this works { Apple, Orange } enum Fruits : Byte // this doesn't work { Apple, Orange } 
+98
Mar 10 2018-10-10T00:
source share

byte and System.Byte identical in C #. byte is just syntactic sugar and is recommended by StyleCop (for style guides).

+19
Mar 10 '10 at 9:30
source share

No difference. byte is an alias of System.Byte, in the same way int is an alias of System.Int32, long for System.Int64, string for System.String, ...

+4
Mar 10 '10 at 9:30
source share

C # has a number of aliases for .NET types. byte is an alias for byte , since string is an alias for string , and int is an alias for Int32 . That is, byte and byte are the same actual type.

+4
Mar 10 '10 at 9:30
source share

Nothing, lowercase is a keyword that is an alias for a byte type.

This is pure syntactic sugar.

+4
Mar 10 '10 at 9:30
source share

They are usually the same.

+3
Mar 10 '10 at 9:30
source share

byte is a built-in data type in C #.
System.Byte is a framework that represents byte and provides additional methods such as Parse and TryParse .

byte is an alias of the System.Byte structure. Different .NET languages ​​have different aliases based on the semantics of a particular language, but they are all mapped to specific types in the .NET framework.

0
Mar 10 '10 at 9:49
source share

also when using reflection ,,

 Type t=Type.GetType("System.Byte"); //works Type t=Type.GetType("System.byte"); //doesn't work, I can see no way to use"byte" directly here without converting it to "Byte" 
0
Apr 26 2018-11-21T00:
source share



All Articles