Challenge 47 – Tuples of Fun
This Challenge creates a function that takes in Tuple representation of an object that contains the following information.
The Tuple<T> class was introduced in .NET Framework 4.0. A tuple is a data structure that contains a sequence of elements of different data types. It can be used where you want to have a data structure to hold an object with properties, but you don’t want to create a separate type for it.
Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
Create a function that takes in Tuple representation of an object that contains the following information:
And returns a string formatted as XML or JSON dependent upon the value of ConvertToXml.
The prototype for the function follows:
- Write a function that will take a Tuple representation of the object discussed above.
- Return a valid Xml or Json formatted string based upon the value of ConvertToXml parameter.
Unfortunately, there were no winners this month. Possibly too hard of a problem.
The following is the solution to the coding challenge. The solution includes a function to transform Tuple to either XML or JSON formatted return, relevant classes to contain input information, and usage example.
Monthly Programming Tips
Enum Flags Attribute
Using the Flags attribute to decorate the enum in C# enables it as bit fields. This enables developers to collect the enum values. One can use the following C# code.
The output for this code will be “BlackMamba, CottonMouth, Wiper”. When the flags attribute is removed, the output will remain 14.
Coding Challenge #48
Please stay tuned, SCS Coding Challenge #48 will be published next week. Details will follow. The winner will be awarded based upon the best approach.