C#: Difference between using System.Text and System.Text.RegularExpressions

前端 未结 3 1285
渐次进展
渐次进展 2021-01-27 14:22

In an ASP.NET C# application, I noticed in order to use Regex and StringBuilder, I had to put both

using System.Text;
using System.Text.RegularExpressions;
         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-27 14:49

    • Regex is defined in System.Text.RegularExpressions
    • StringBuilder is defined in System.Text

    You need to include both namespaces for these two types to be in scope. Including a namespace A.B doesn't automatically include a contained namespace A.B.C. If this were the case, nested namespaces would be of limited use.

提交回复
热议问题