为什么我会收到错误:您是否缺少using指令或程序集引用?

时间:2017-09-11 07:58:07

标签: c# asp.net .net

我在aspx文件中添加了C#代码,但显示错误。

这段代码我添加到asp文件:

   [System.Web.Services.WebMethodAttribute, System.Web.Script.Services.ScriptMethodAttribute]
   public static string[] GetCompletionList(string prefixText, int count)
   {
        string[] names = {"Ram","Ankit","Sam","Sahil","Rajan","Rahul","Sajan"};
        var namesList = from tmp in names where tmp.ToLower().StartWith(prefixText) select tmp;

    return names;
    }

我收到此错误:

Compiler Error Message: CS1061: 'string' does not contain a definition for 'StartWith' and no extension method 'StartWith' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

这是我在页面中宣布的:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="System.Runtime.Serialization" %>
<%@ Import Namespace="System.Text" %>

知道如何修复错误?

1 个答案:

答案 0 :(得分:3)

您忘记了StartsWith - StartWith中的s。