using extension methods on int

后端 未结 7 1195
难免孤独
难免孤独 2021-02-19 04:10

I\'m reading about extension methods, and monkeying around with them to see how they work, and I tried this:

namespace clunk {
    public static class oog {
             


        
7条回答
  •  青春惊慌失措
    2021-02-19 04:38

    Console.WriteLine(5.doubleMe());

    is equivalent to

    Console.WriteLine(oog.doubleMe(5));

    Given that, you can see why if ( 7 ) doesn't work.

    Extension methods are nothing more than syntax.

    As a side note since it is syntax you can call extension methods on null variables because it translates to a normal method call, and methods can take null parameters.

提交回复
热议问题