Hello dear members.
I am very new to C # programming. I cannot complete my program below. At the same time, I cannot explain my problem.
The output I desire:
How should I fill in the XXX, YYY, ZZZ fields?
i’d use array of Types instead of strings (you can use “typeof(int)” to get the Type instance for int type, for example) and then enumerate through the properties using Reflection and look for the .MinValue and .MaxValue
by quick google, this page seems to have code on how to get the value once you have the property name: https://developerpublish.com/c-tips-and-tricks-12-get-property-value-using-reflection/
Thank you for your response, how can I declare “array of Types”?
Similarly, if you’re using reflection anyway, you can make an array of Objects. The benefit here is that then you can reflect, use static methods/properties, or use instance methods/properties (if you were to expand on this). E.g.:
Object[] types = {
new sbyte(),
new byte(),
new short(),
new ushort(),
new int(),
new uint(),
new long(),
new ulong(),
new float(),
new double(),
new decimal() };
Already some good answers here, so I’ll tackle another question.
Explaining your problem is also something you should be able to do well :).
In this case, you want to list the Min and Max values of numeric types, without having to do it manually.
On that note, Types in C# are more that just decoration and well, typing, they are a whole Type System, with information accessible through Reflection. They can be used in variables, as parameters, and of course there is Generics.
The most naive way would be to use a bunch of if statements. I guess your task is to do it with if statements. You have to be able to explain the solution you use so beware of the advanced solutions above. They are great but would a beginner do it that way ?
Just write a function and inside that function check the array element. Write out the appropriate information.