Extension Methods not Recognized

前端 未结 12 1006
抹茶落季
抹茶落季 2020-12-10 00:09

What is necessary to have an extension method honored when it exists in an imported assembly? I built one in a class library project but it is not recognized in my web proj

12条回答
  •  醉梦人生
    2020-12-10 01:09

    Referencing an assembly containing a class with extension methods is not enough. You need to import the namespace containing the class in each of your source file where you want to use the extension methods.

    For example, to use LINQ-to-objects, you need to reference the System.Core assembly and import the System.Linq namespace (which contains the Enumerable class with the LINQ extension methods):

    using System.Linq;
    

提交回复
热议问题