Detailed explanation of C for String type addition method

  • 2021-10-27 08:37:50
  • OfStack


namespace MyExtensionMethods 
{ 
  public static class MyExtensions 
  { 
    public static int MyGetLength(this System.String target) 
    { 
      return target.Length; 
    } 
  } 
} 

When you use it, you need to introduce this namespace, which is referenced as follows:


string str = "dafasdf"; 
int len = str.MyGetLength(); 

Related articles: