Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- class FileStreamReadLine
- {
- static void Main()
- {
- object[] allTypes = { "Name", "NoName", "No-Name", 23, "naTe", "No-naTe", "Nema-naTe", 32, 12, 231,
- 0.0001f, (float)0.001, 12.0000001, 10.000000001,
- 0.00000000000000000001m, (decimal)1.00000000000000000001,
- 'a', 'b', 'c', 'd', (byte)1, (byte)2, (byte)3, 123L, 234L, (long)110, 222, 333L};
- string str = string.Empty;
- string concatChars = string.Empty;
- byte sumByte = 0;
- int sumInts = 0;
- long sumLongs = 0;
- float sumFloats = 0;
- double sumDoubles = 0;
- decimal sumDecimal = 0;
- for (int i = 0; i < allTypes.Length; i++)
- {
- if (allTypes[i] is string)
- {
- str += allTypes[i] + ", ";
- }
- else if (allTypes[i] is char)
- {
- concatChars += allTypes[i] + "; ";
- }
- else if (allTypes[i] is byte)
- {
- sumByte += (byte)allTypes[i];
- }
- else if (allTypes[i] is int)
- {
- sumInts += (int)allTypes[i];
- }
- else if (allTypes[i] is long)
- {
- sumLongs += (long)allTypes[i];
- }
- else if (allTypes[i] is float)
- {
- sumFloats += (float)allTypes[i];
- }
- else if (allTypes[i] is double)
- {
- sumDoubles += (double)allTypes[i];
- }
- else if (allTypes[i] is decimal)
- {
- sumDecimal += (decimal)allTypes[i];
- }
- else
- {
- Console.WriteLine("{0} --> Unknown value!.?.!?", allTypes[i]);
- }
- }
- Console.WriteLine("Strings ==> {0}", str);
- Console.WriteLine("Chars ==> {0}", concatChars);
- Console.WriteLine("Sum of int values: {0}", sumInts);
- Console.WriteLine("Sum of byte values: {0}", sumByte);
- Console.WriteLine("Sum of long values: {0}", sumLongs);
- Console.WriteLine("Sum of float values: {0}", sumFloats);
- Console.WriteLine("Sum of double values: {0}", sumDoubles);
- Console.WriteLine("Sum of decimal values: {0}", sumDecimal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement