mozingo
link
fedilink
English
281Y

This sure looks like C#. I use typeof every once in a while when I want to check that the type of a reference is a specific type and not a parent or derived type. But yea, really not that often.

It looks exactly like c++ and c# and java and probably others.

Typescript! Though it’s less useful, since the Typescript types aren’t available at runtime, so you’ll just get object for non-primitive values.

Java only has instanceof and getClass, not typeof.

Probably because Java and C# take much inspiration from C++. They aren’t called “C-based” languages for nothing 😉

mozingo
link
fedilink
English
71Y

But neither c++ or Java have typeof

m_r_butts
link
fedilink
3
edit-2
1Y

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]”.

@tonur@feddit.dk
link
fedilink
English
31Y

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.

m_r_butts
link
fedilink
21Y

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.

Create a post

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

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 82 users / day
  • 214 users / week
  • 415 users / month
  • 2.93K users / 6 months
  • 1 subscriber
  • 1.53K Posts
  • 33.8K Comments
  • Modlog