C# – DefaultMemberAttribute – what does it do

.net, attributes, c++, vb.net

I've already read the MSDN article about it. It seems internally it is the way c# sets which is the function that is going to work as indexer(am I right?). Now, I've seen the following example:

[DefaultMemberAttribute("Main")]public class Program {    public static void Main() {        ...    }}

Now, I don't get it what it means.


Thanks all. But I still can't get its usefulness, apart from the indexer thing. When are we going to call InvokeMember?

Best Solution

I personally have never used it, but as far as I can tell you are defining the default method to be invoked when calling InvokeMember. So, using the code snippet you provided if I was to say:

Program prog = new Program();typeof(Program).InvokeMember("", null, null, prog, null);

Because I left the first argument empty of the InvokeMember call it would use the attribute to determine what the default member is of your class, in your case it is Main.