qqffx
0
Q:

c# extension

public static class MyClassExtension
{
  // This is the method you are adding to a class "MyClass"
  public static string GetValue(this MyClass myClass)
  {
    return value.toString();
  }
}

// This is how you can use it in other parts of your code
MyClass myClass = new MyClass();
string s = myClass.GetValue();
1
public static class MyExtensions
{
  //use the this keyword before an argument
  public static int WordCount(this String str)
  {
    return str.Split(new char[] { ' ', '.', '?' },
                     StringSplitOptions.RemoveEmptyEntries).Length;
  }
}
1

New to Communities?

Join the community