Lower case "byte" is a built in type in C#. System.Byte is a class built into the .NET framework that represents a byte. The secret is that this built in type is an alias to the System.Byte class. Different .NET languages have different aliases based on the semantics of the particular language, but they all map to specific object types in the .NET framework. This allows code to be written more "cleanly" and still easily compile to the correct type in the .NET framework.
Let's confirm the statement that the C# built in type 'byte' is really an alias of the System.Byte class.
byte and System.Byte Example
using System;
using System.Collections.Generic;
using System.Text;
namespace ByteDifferenceExample
{
class Program
{
static void Main(string[] args)
{
byte small_b_byte = 1;
Byte large_b_byte = 2;
Console.WriteLine("The value of the little b byte is: " + small_b_byte);
Console.WriteLine("The type of the little b byte is: " + small_b_byte.GetType());
Console.WriteLine("----------------------------");
Console.WriteLine("The value of the big b byte is: " + large_b_byte);
Console.WriteLine("The type of the big b byte is: " + large_b_byte.GetType());
Console.WriteLine("----------------------------");
if (small_b_byte.GetType() == large_b_byte.GetType())
{
Console.WriteLine("Summary: byte and Byte have the same type!");
}
else
{
Console.WriteLine("Summary: byte and Byte have different types");
}
}
}
}
Output of byte and System.Byte Example
The value of the little b byte is: 1
The type of the little b byte is: System.Byte
----------------------------
The value of the big b byte is: 2
The type of the big b byte is: System.Byte
----------------------------
Summary: byte and Byte have the same type!
Additional Resources
Built-In Types Table, C# (Microsoft)
3 comments:
Thanks for the info. When are you going to post the code sample?
It is there now :) Sometimes I write the article before I have a chance to write the code sample :)
Finally found you... a friend said you were good enough to help me.
You know where to find me.
Post a Comment