Advertisement
GogoK

objectAndTypes

Nov 4th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5.  
  6. class FileStreamReadLine
  7. {
  8.     static void Main()
  9.     {
  10.         object[] allTypes = { "Name", "NoName", "No-Name", 23, "naTe", "No-naTe", "Nema-naTe", 32, 12, 231,
  11.                                 0.0001f, (float)0.001, 12.0000001, 10.000000001,
  12.                                 0.00000000000000000001m, (decimal)1.00000000000000000001,
  13.                                 'a', 'b', 'c', 'd', (byte)1, (byte)2, (byte)3, 123L, 234L, (long)110, 222, 333L};
  14.  
  15.         string str = string.Empty;
  16.         string concatChars = string.Empty;
  17.         byte sumByte = 0;
  18.         int sumInts = 0;
  19.         long sumLongs = 0;
  20.         float sumFloats = 0;
  21.         double sumDoubles = 0;
  22.         decimal sumDecimal = 0;
  23.  
  24.         for (int i = 0; i < allTypes.Length; i++)
  25.         {
  26.             if (allTypes[i] is string)
  27.             {
  28.                 str += allTypes[i] + ", ";
  29.             }
  30.             else if (allTypes[i] is char)
  31.             {
  32.                 concatChars += allTypes[i] + ";  ";
  33.             }
  34.             else if (allTypes[i] is byte)
  35.             {
  36.                 sumByte += (byte)allTypes[i];
  37.             }
  38.             else if (allTypes[i] is int)
  39.             {
  40.                 sumInts += (int)allTypes[i];
  41.             }
  42.             else if (allTypes[i] is long)
  43.             {
  44.                 sumLongs += (long)allTypes[i];
  45.             }
  46.             else if (allTypes[i] is float)
  47.             {
  48.                 sumFloats += (float)allTypes[i];
  49.             }
  50.             else if (allTypes[i] is double)
  51.             {
  52.                 sumDoubles += (double)allTypes[i];
  53.             }
  54.             else if (allTypes[i] is decimal)
  55.             {
  56.                 sumDecimal += (decimal)allTypes[i];
  57.             }
  58.             else
  59.             {
  60.                 Console.WriteLine("{0} --> Unknown value!.?.!?", allTypes[i]);
  61.             }
  62.         }
  63.         Console.WriteLine("Strings ==> {0}", str);
  64.         Console.WriteLine("Chars ==> {0}", concatChars);
  65.         Console.WriteLine("Sum of int values:   {0}", sumInts);
  66.         Console.WriteLine("Sum of byte values:   {0}", sumByte);
  67.         Console.WriteLine("Sum of long values:   {0}", sumLongs);
  68.         Console.WriteLine("Sum of float values:   {0}", sumFloats);
  69.         Console.WriteLine("Sum of double values:   {0}", sumDoubles);
  70.         Console.WriteLine("Sum of decimal values:   {0}", sumDecimal);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement