+ 9

Why C# is not taking 'T' as a generic?

I thought I understood C# generics well enough.... until I made my own code. Why is C# taking T as a typename rather than a generic in the mentioned code(I hope I stated that correctly)? I tried a lot, but I can't seem to find what the problem is? https://code.sololearn.com/c4qcwty78Vb0/?ref=app

19th Jan 2020, 7:59 AM
XXX
XXX - avatar
11 Antworten
+ 14
XXX I explain the issue here in a recorded video. https://www.sololearn.com/post/223795/
20th Jan 2020, 12:23 AM
David Carroll
David Carroll - avatar
+ 3
David Carroll thanks a lot. And i fixed the bug.
20th Jan 2020, 10:28 AM
XXX
XXX - avatar
+ 2
I am not really sure but shouldn't you use <T>
19th Jan 2020, 11:34 AM
Mihai Apostol
Mihai Apostol - avatar
+ 2
Here's a workaround but just for the comparing. As I see the sorting is not quite well. Anyhow I'm no expert, just a fellow sololearner trying to help, and learn while helping. https://code.sololearn.com/cj959AN1U57g/?ref=app
19th Jan 2020, 1:25 PM
Mihai Apostol
Mihai Apostol - avatar
+ 2
But you ultimately converted the parameters to Integer. What if I give a float as argument? Still thanks for your time. I still can't understand what's wrong with my code.
19th Jan 2020, 2:52 PM
XXX
XXX - avatar
+ 2
20th Jan 2020, 12:29 AM
David Carroll
David Carroll - avatar
+ 2
It was a very silly bug after all. Thanks.
20th Jan 2020, 2:16 PM
XXX
XXX - avatar
+ 1
Mihai Apostol just tried that. Still showing operator '>' is not allowed for operands of type 'typ'(I renamed T to typ)
19th Jan 2020, 12:57 PM
XXX
XXX - avatar
+ 1
XXX Nice... I had an earlier recording attempt where I mentioned how to fix your sorting issue. However, the recording was cut off before I could finish explaining the issue regarding constraints. So, I left the final recording focused on just generic constraints. Plus, I figured you would want to fix the bug with sorting on your own anyway.
20th Jan 2020, 1:25 PM
David Carroll
David Carroll - avatar
+ 1
wow. That's really cumbersome. I'd stop defending C# after this, David Carroll 😃 I'm joking, btw ☺
20th Jan 2020, 8:21 PM
Selin Genkur
+ 1
Selin Genkur It's actually quite brilliant when viewed in more practical scenarios. Not that this is invalid. It's just not possible to see the elegance of static code in a clearer context with code in single file, narrow width format on Playground.
20th Jan 2020, 10:05 PM
David Carroll
David Carroll - avatar