



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




02 Handout 1 _Property of STI_*
Code Listing 1. Sample class with identifiers using System; namespace ConsoleApp { class ComputeRectangleArea { static void Main() { int length, width, area; length = 50; width = 8; area = length * width; Console.WriteLine("The area of the rectangle is " + area); Console.ReadKey(); } } }
Table 1. Example valid identifiers Table 2. Example invalid identifiers
abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void volatile while Table 3. C# keywords (Harwani, 2015)
02 Handout 1 _Property of STI_*
data_type identifier;
Figure 1. Memory allocation for value type
02 Handout 1 _Property of STI_*
From To Example int (^) long, float, or double int a = 25; double b = a; //the value of b is 25. uint (^) long, ulong, float, or double uint a = 25; long b = a; long float or double long a = 25; double b = a; ulong (^) float or double ulong a = 25; double b = a; float double float a = 25.0F; double b = a; char (^) ushort, int, uint, long, ulong, float, or double char a = 'a'; int b = a; //the value of b is 97 because the decimal value of character 'a' in ASCII table is 97 Table 5. Implicit numeric conversions (Deitel, P. and Deitel, H., 2015)
(data_type) data_to_convert;
int num = 25; byte b = (byte) num; //second example double price = 75.5; int varA = (int) price; //the value of variable a will be 75
int a = (int) 7.9; //the return value of a is 7 double b = (double) (5 + 3); //the value of b is 8. Console.WriteLine((int) 2.5); //the output is 2 int c = 64; char d = (char) c; //the return value of d is the character '@'
02 Handout 1 _Property of STI_*
Table 6. Explicit conversions (Deitel, P. and Deitel, H., 2015)
int a = 64; char b = (char) a; //the value of b is the character '@' because it is the corresponding character of decimal value 64 in ASCII table