class ExtensionMethods2    
{

static void Main()
{
int[] ints = { 10, 45, 15, 39, 21, 26 };
var result
= ints.OrderBy(g => g);
foreach (var i in result)
{
System.Console.Write(i
+ " ");
}
}
}
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' },
StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}

要使用时只需要要:
string s = "Hello Extension Methods";
int i = s.WordCount();

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-10-08
  • 2021-08-16
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2021-12-19
  • 2022-01-29
  • 2021-05-24
相关资源
相似解决方案