About 53 results
Open links in new tab
  1. c# - Type Checking: typeof, GetType, or is? - Stack Overflow

    Use typeof when you want to get the type at compilation time. Use GetType when you want to get the type at execution time. There are rarely any cases to use is as it does a cast and, in most cases, you …

  2. c# - When and where to use GetType () or typeof ()? - Stack Overflow

    Jul 3, 2012 · 151 typeof is an operator to obtain a type known at compile-time (or at least a generic type parameter). The operand of typeof is always the name of a type or type parameter - never an …

  3. c# - What is the difference of getting Type by using GetType () and ...

    Dec 27, 2010 · They both return System.Type object. However, typeof is used to return the type object representing a given type (int, bool, string, float, UserDefinedType like a class).</br> Forexample: …

  4. c# - How to switch on System.Type? - Stack Overflow

    In C# 7+, can I switch directly on a System.Type? When I try: switch (Type) { case typeof(int): break; } it tells me that typeof(int) needs to be a constant expression. Is

  5. Reflection of C# Types: GetType( "myType" ) vs typeof( myType ...

    May 30, 2013 · My question is why does the static GetType (string) method return null, while if I hard-code the namespace and class and use typeof () as in the if statement, I get the required result?

  6. c# - Difference between nameof and typeof - Stack Overflow

    Nov 11, 2015 · 0 Typeof returns Type objects. It is often used as a parameter or as a variable or field. The typeof operator is part of an expression that acquires the Type pointer. Nameof, meanwhile, …

  7. c# - How does 'typeof' work? - Stack Overflow

    Jun 30, 2010 · 15 I am curious what the "method body" for typeof in C# would look like (pretty sure I can't get to it in reflector as it's a keyword not a method). I am guessing it is equivalent to GetType …

  8. C#.NET - How can I get typeof () to work with inheritance?

    C#.NET - How can I get typeof () to work with inheritance? Asked 16 years, 8 months ago Modified 10 years, 5 months ago Viewed 24k times

  9. c# - How to tell whether a Type is a list or array or IEnumerable or ...

    Nov 7, 2010 · What's the easiest way, given a Type object, to test to see whether it is actually a list of objects? I.e. Array or IEnumerable/IEnumerable&lt;>.

  10. c# - Which is faster between is and typeof - Stack Overflow

    Mar 18, 2022 · Does it matter which is faster, if they don't do the same thing? Comparing the performance of statements with different meaning seems like a bad idea. is tells you if the object …