this post was submitted on 28 Nov 2023
555 points (97.9% liked)

Programmer Humor

32000 readers
1744 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 9 months ago* (last edited 9 months ago) (2 children)

It can't be actual C#, but it does look like it.

If you declare a class Pie<T>{} then attempt to call typeof(Pie<T>) or typeof(T) it won't even build because you failed to specify what type T is. typeof(Pie<object>) would work but that just returns "Pie1[System.Object]".

[–] [email protected] 5 points 9 months ago (1 children)

I have used typeof(T) inside the generic class, so fx a function inside the class Pie where T can be refered. But out of context, if you were to call typeof(T) inside Program.cs's main function, it would not work.

[–] [email protected] 3 points 9 months ago

Yeah, but to do that you'd need an instantiated instance of the Pie class, which would answer in the context of the generic type parameter, not the whole Pie class.

This is too funny. Everyone here, me included, is profoundly overthinking this, lol.

[–] [email protected] 1 points 9 months ago* (last edited 9 months ago) (1 children)

I don't get what you mean. You can define class Pie and instantiate it with the type argument Pie.

Huh, maybe I don't get it because Lemmy is literally erasing angle brackets from our messages. Not just "not rendering." It's removing them entirely. There should be four angle brackets in the first line of this comment...

[–] [email protected] 1 points 9 months ago

Dunno. I'm on Kbin. It looks okay here.