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.
I’m working on a background fun project where there’s a base class that is for olde style CPU emulation. Where you can derive a class from the base class and essentially design 8bit style CPUs.
I have a separate class as a generic Assembler that will work with any of the created CPUs. But, to be able to do that I need to be able to get information about instructions, arguments, opcodes, registers etc from the derived class.
So the assembler is instantiated with Assembler\ and then it uses typeof to instantiate the actual CPU class being used to get all the information.
So, that’s just an example of when you’d use something like this.
I have used typeof(T) inside the generic class, so fx a function inside the classPie 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.
I don’t get what you mean. You can define classPie 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…
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.
Java only has
instanceof
andgetClass
, not typeof.But neither c++ or Java have typeof
deleted by creator
Standard C does not have typeof. That’s just a compiler extension…
Also the equivalent of typeof is most likely decltype or auto.
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.Probably because Java and C# take much inspiration from C++. They aren’t called “C-based” languages for nothing 😉
Yeah in C# it has quite a few uses.
I’m working on a background fun project where there’s a base class that is for olde style CPU emulation. Where you can derive a class from the base class and essentially design 8bit style CPUs.
I have a separate class as a generic Assembler that will work with any of the created CPUs. But, to be able to do that I need to be able to get information about instructions, arguments, opcodes, registers etc from the derived class.
So the assembler is instantiated with Assembler\ and then it uses typeof to instantiate the actual CPU class being used to get all the information.
So, that’s just an example of when you’d use something like this.
deleted by creator
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.deleted by creator
I don’t get what you mean. You can define
class Pie
and instantiate it with the type argumentPie
.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…
deleted by creator