Hi everyone,
I want to build a example about Generics Constraint with the question:
How will the complier catch a error when user input string type but reasonable with int, float, double, long type?
Can you help me this problem?
Many thanks.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 8:05 PM EDT
I am not clear about your query. Can you please explain bit more?
Regards,
Iftikar
Cuong Pham15 reputationPosted Aug 15, 2013, 8:28 PM EDT
It means that you can initialize a object with string type, the compile time will catch error.
ex: Create a class Compare two number
and then in Main method:
ObjectClass
ObjectClass
ObjectClass
ObjectClass
but:
ObjectClass
It only supports int, float, long, double.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 8:55 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:01 PM EDT
http://www.c-sharpcorner.com/uploadfile/yougerthen/using-icomparable-and-icomparer-to-compare-objects/
Regards,
Iftikar
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2013, 11:13 PM EDT
Cuong Pham15 reputationPosted Aug 15, 2013, 11:50 PM EDT
Best wishes for u !