05 C Basics Part II PDF
05 C Basics Part II PDF
Object Oriented
Programming I
C# Basics
-
Part II
Öğr. Gör.
İhsan Can İÇİUYAN
2 Object Oriented Programming
Contents
System Data Types
BigInteger
Digit Separators
Binary Literals
3 Object Oriented Programming
It is also possible to allocate any data type using its full name:
System.Boolean b4 = false;
Code: 11_VarDeclarations.cs
Output:
Your data: 0, This is my character data, True, False, True, False
7 Object Oriented Programming
You can also create a variable using the new keyword, which
automatically sets the variable to its default value:
bool variables are set to false.
Numeric data is set to 0 (or 0.0).
char variables are set to a single empty character.
BigInteger variables are set to 0.
DateTime variables are set to 1/1/0001 12:00:00 AM.
Object references (including strings) are set to null.
8 Object Oriented Programming
System.Double type allows you to obtain the values for epsilon and
infinity.
You can use the static Parse() method to convert a string into the
underlying data type.
BigInteger
BigInteger → to represent huge numerical values, which are not
constrained by a fixed upper or lower limit
BigInteger biggy =
BigInteger.Parse("9999999999999999999999999999999999999999999999");
BigInteger
Consider the following example:
BigInteger biggy =
BigInteger.Parse("9999999999999999999999999999999999999999999999");
Console.WriteLine("Value of biggy is {0}", biggy);
Console.WriteLine("Is biggy an even value?: {0}", biggy.IsEven);
Console.WriteLine("Is biggy a power of two?: {0}", biggy.IsPowerOfTwo);
Digit Separators
Sometimes when assigning large numbers to a numeric variable,
there are more digits than the eye can keep track of.
e.g. 1234567, 24356378, 9245673.3467
Console.Write("Integer:");
Console.WriteLine(123_456);
Console.Write("Long:");
Console.WriteLine(123_456_789L);
Console.Write("Float:");
Console.WriteLine(123_456.1234F);
Console.Write("Double:");
Console.WriteLine(123_456.12);
Console.Write("Decimal:");
Console.WriteLine(123_456.12M);
Console.Write("Hex:");
Console.WriteLine(0x_00_00_FF);
23 Object Oriented Programming
Binary Literals
Binary numbers can be written as follows:
0b_0001_0000
References
Built-in types, https://learn.microsoft.com/en-us/dotnet/csharp/language-
reference/builtin-types/built-in-types