none
What is special about the System.Type objects? And what are method group names? RRS feed

  • Question

  • Hello. I'm reading the C# Docs and I've encountered this sentence: "although a namespace name is classified as an expression, it does not evaluate to a value and therefore can never be the final result of any expression. You cannot pass a namespace name to a method parameter, or use it in a new expression, or assign it to a variable. You can only use it as a sub-expression in a larger expression. The same is true for types (as distinct from System.Type objects), method group names (as distinct from specific methods)" 

    "The same is true for types (as distinct from System.Type objects)" What does that exactly mean? Can you show example of this with the System.Type? It has something to do with the Reflection? right? 

    Also what are method group names and specific methods? 

    Saturday, February 17, 2018 8:19 PM

All replies

  • Yes the System.Typeis related to Reflection and  holds the meta data of type. You can get an instance of it  using thetypeof()  method which would take the class name as input like:

    public class Program
    {
       public  static void Main(String[] args)
       {
         Type type = typeof(Program);
       }
    }

    and we can also get  it's  instance using the GetType() method on any object in C# like:

    public class Program
    {
       public  static void Main(String[] args)
       {
         Type type = this.GetType();
         Type argsType = args.GetType();
       }
    }

    and  for method group:

    A method group is the name for a set of methods (that might be just one) - i.e. in theory the ToString method may have multiple overloads (plus any extension methods): ToString(), ToString(string format), etc - hence ToString by itself is a "method group".

    For  more details, refer to the  following  post:

    What is a Methood Group in C# ?

    Hope  it  helps!


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites



    Sunday, February 18, 2018 9:17 AM