public string Display() { string consoleText = ""; var list = new List <object> { new Something("val one", "val two"), 2, false, 3.2, 3.2f, 3.2m, 's', "something", new StructExaple("struct val one", "struct val two") }; IEnumerable <object> items = new EnumerableExample <object>(list); consoleText += DisplayFormatHelpers.DescriptionValueFormat ( "Raw list: ", DisplayFormatHelpers.WriteList(list) ); consoleText += DisplayFormatHelpers.DescriptionValueFormat ( "Printing the above list using the custom .ToString(): ", items ); return(consoleText); }
public string Display() { // IEnumerable only allows the given object to be iterated (usually with a foreach) var displayText = ""; IList <int> dummyData = new List <int>() { 0, 6, 7, 1, 8, 9, 4, 7, 7, 1, 5, 8, 2 }; displayText += DisplayFormatHelpers.DescriptionValueFormat( "Initial List", DisplayFormatHelpers.WriteList(dummyData) ); var whereResults = Where <int>(dummyData, (i) => i >= 5); displayText += DisplayFormatHelpers.DescriptionValueFormat( "Using the Where<T>() method to keep values which are >= 5 only || Where<int>(dummyData, (i) => i >= 5 );", DisplayFormatHelpers.WriteList(whereResults) ); var whereExtensionResult = dummyData.Where((i) => i >= 5); displayText += DisplayFormatHelpers.DescriptionValueFormat( "Using the .Where() extension to achieve the same result || dummyData.Where((i) => i >= 5);", DisplayFormatHelpers.WriteList(whereExtensionResult) ); return(displayText); }
public string Display() { var consoleText = ""; int num = 42; consoleText += DisplayFormatHelpers.DescriptionValueFormat("Integer before using the extension method AddOne()", num.ToString()); num = num.AddOne(); consoleText += DisplayFormatHelpers.DescriptionValueFormat("Integer after using the extension method AddOne()", num.ToString()); return(consoleText); }
public string Display() { var displayText = ""; IList <Car> carList = new Car[] { new Car() { Brand = "Toyota", Make = "Prius" }, new Car() { Brand = "Subaru", Make = "Impreza" }, new Car() { Brand = "Mitsubishi", Make = "Lancer" }, new Car() { Brand = "Skoda", Make = "Octavia" }, new Car() { Brand = "VW", Make = "Golf" }, new Car() { Brand = "Nissan", Make = "GTR" } }; displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Raw object (using fields)", DisplayFormatHelpers.WriteList(carList) ); var convertor = new ObjectListToCsv <Car>(carList); displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Object list to CSV format", convertor.ToCsv() ); return(displayText); }
public string Display() { // IEnumerable only allows the given object to be iterated (usually with a foreach) var displayText = ""; IList <string> listExample = new List <string>() { "one", "two", "three", "four" }; displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Initial list which implements the IList interface", DisplayFormatHelpers.WriteList <string>(listExample) ); Console.WriteLine(listExample[2]); displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Access item by index, [2]", listExample[2] ); //listExmaple.IndexOf("two"); Console.WriteLine(listExample[2]); displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Get index of a specific item, \"three\"", listExample.IndexOf("three") ); //listExmaple.Insert(1, "inserted item"); listExample.Insert(2, "inserted"); displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Insert item at a specific index, \"inserted\" at [2]", DisplayFormatHelpers.WriteList <string>(listExample) ); //listExmaple.RemoveAt(3); listExample.RemoveAt(3); displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Remove the item at index [3]", DisplayFormatHelpers.WriteList <string>(listExample) ); return(displayText); }
public string Display() { string consoleText = ""; int i = 42; object boxedI = i; int unboxedI = (int)boxedI; try { string wrongFormatToUnbox = (string)boxedI; } catch (InvalidCastException ex) { consoleText += DisplayFormatHelpers.DescriptionValueFormat("Trying to unbox with a wrong type", ex.Message); } return(consoleText); }
public string Display() { string consoleText = ""; Example exampleInstance = new Example(); IOne exampleIOne = exampleInstance; ITwo exampleITwo = exampleInstance; consoleText += DisplayFormatHelpers.DescriptionValueFormat( "Accessing the method explicitly using the type of the variable", exampleIOne.SaySomething() ); consoleText += DisplayFormatHelpers.DescriptionValueFormat( "Accessing the method explicitly by type casting the class itself", ((ITwo)exampleInstance).SaySomething() ); return(consoleText); }
public string Display() { // IEnumerable only allows the given object to be iterated (usually with a foreach) var displayText = ""; IEnumerable enumClass = new RandomNumbers(1, 10, 5); List <int> randNums = new List <int>(5); foreach (int randNum in enumClass) { randNums.Add(randNum); } displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Iterating over the custom iterable class using a foreach", DisplayFormatHelpers.WriteList(randNums) ); Console.WriteLine("\n\n\n"); IEnumerable enumClass2 = new RandomNumbers(1, 3, 10); List <int> randNums2 = new List <int>(5); IEnumerator enumClass2Enumerator = enumClass2.GetEnumerator(); while (enumClass2Enumerator.MoveNext()) { randNums2.Add((int)enumClass2Enumerator.Current); } displayText += DisplayFormatHelpers.DescriptionValueFormat ( "Iterating over the custom iterable class using a while loop", DisplayFormatHelpers.WriteList(randNums2) ); return(displayText); }
public string Display() { var displayText = ""; var someList = new List <string> { "one", "two", "three", "four", "five" }; displayText += DisplayFormatHelpers.DescriptionValueFormat ( "List, type: " + someList.GetType().ToString(), DisplayFormatHelpers.WriteList(someList) ); string[] someListArray = someList.ToArray(); displayText += DisplayFormatHelpers.DescriptionValueFormat ( "List to array, type: " + someListArray.GetType().ToString(), DisplayFormatHelpers.WriteList <string>(someListArray) ); return(displayText); }