Primitive types
/csbook/solutions/03/A02.cs
using System;
using System.IO;
using System.Text;
class Test {
public static void Main() {
// minimum and maximum values
Console.WriteLine("int: MinValue = {0}, MaxValue = {1}",
Int32.MinValue, Int32.MaxValue);
Console.WriteLine("float: MinValue = {0:E5}, MaxValue = {1:E5}",
Single.MinValue, Single.MaxValue);
Console.WriteLine("char: MinValue = {0}, MaxValue = {1}",
(int)Char.MinValue, (int)Char.MaxValue);
// base types
Console.WriteLine("base type of int: " + 3.GetType().BaseType.FullName);
Console.WriteLine("base type of float: " + 3f.GetType().BaseType.FullName);
Console.WriteLine("base type of char: " + 'x'.GetType().BaseType.FullName);
// reading a word; lower-case letters are converted to upper-case letters
StreamReader r = File.OpenText("input.txt");
StringBuilder buf = new StringBuilder();
int ch = r.Read();
while (ch >= 0) {
if (Char.IsLetterOrDigit((char)ch)) {
if (Char.IsLower((char)ch)) ch = Char.ToUpper((char)ch);
buf.Append((char)ch);
}
ch = r.Read();
}
Console.WriteLine(buf.ToString());
r.Close();
}
}
|
Executing this program with the file input.txt containing
the value route66 yields the following output:
int: MinValue = -2147483648, MaxValue = 2147483647
float: MinValue = -3.40282E+038, MaxValue = 3.40282E+038
char: MinValue = 0, MaxValue = 65535
base type of int: System.ValueType
base type of float: System.ValueType
base type of char: System.ValueType
ROUTE66
|