How Can I inherit the string class?

后端 未结 7 2088
春和景丽
春和景丽 2020-12-03 10:03

I want to inherit to extend the C# string class to add methods like WordCount() and several many others but I keep getting this error:

Er

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 10:40

    You cannot derive from string, but you can add extensions like:

    public static class StringExtensions
    {
        public static int WordCount(this string str)
        {
        }
    }
    

提交回复
热议问题