Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么对方法或属性的调用不明确?(C#)_C#_Asp.net - Fatal编程技术网

为什么对方法或属性的调用不明确?(C#)

为什么对方法或属性的调用不明确?(C#),c#,asp.net,C#,Asp.net,无法理解为什么我的代码会说某个方法或属性不明确。如果有人能告诉我原因并解释一下,那就太好了。我对这两种方法有意见: PostCodeInfo MatchingPostCode = Find(PostCodeList, PostCode); PostCodeInfo MatchingPostCode2 = Find(PostCodeList, PostCode2); 上下文的完整代码: namespace GetPost { public cl

无法理解为什么我的代码会说某个方法或属性不明确。如果有人能告诉我原因并解释一下,那就太好了。我对这两种方法有意见:

        PostCodeInfo MatchingPostCode = Find(PostCodeList, PostCode);


        PostCodeInfo MatchingPostCode2 = Find(PostCodeList, PostCode2);
上下文的完整代码:

    namespace GetPost
{
    public class PostCodeInfo
    {
        public string PostCode { get; set; }
        public string Locality { get; set; }
        public string State { get; set; }
        public string PostCode2 { get; set; }




        public PostCodeInfo(string postCode, string postcode2, string locality, string state)
        {
            PostCode = postCode;
            PostCode2 = postcode2; 
            Locality = locality;
            State = state;


        }
    }



    public partial class WebForm1 : System.Web.UI.Page
    {
        protected static List<PostCodeInfo> PostCodeList;

        protected bool Contains(List<PostCodeInfo> listToCheck, string postCode)
        { //This is a very slow search that you normally wouldn't use, but to keep things simple we'll just iterate through every list item and check for our post code
            foreach (PostCodeInfo entry in listToCheck)
                if (entry.PostCode == postCode)
                    return true;
            return false;
        }




        protected void Load_Postcodes(string CSVFileName)
        {
            PostCodeList = new List<PostCodeInfo>();

            StreamReader Reader = null;
            try
            {
                Reader = new StreamReader(CSVFileName);
            }
            catch (FileNotFoundException ex)
            {
                lblOutput.Text = string.Format("Error: Check your file path and file name for the post code CSV are correct! Current setting is: '{0}'", CSVFileName);
                return;
            }
            Reader.ReadLine(); //Get rid of the first line of the file which contains the names of the columns (e.g. "Pcode", "Locality" , etc.)
            while (Reader.EndOfStream == false)
            {
                string CurrentLine = Reader.ReadLine();
                string[] Columns = CurrentLine.Split(new char[] {','});
                for (int i = 0; i < Columns.Length; i++)
                { //Remove the redundant double quotes included in the CSV file
                    Columns[i] = Columns[i].TrimStart(new char[] { '"' });
                    Columns[i] = Columns[i].TrimEnd(new char[] { '"' });
                }
                PostCodeInfo NewPostCode = new PostCodeInfo(Columns[0], Columns[1], Columns[2], Columns[3]); //Consider error checking each column in your assignments
                if (Contains(PostCodeList, NewPostCode.PostCode) == false)
                { //Don't add the PostCodeInfo if we already encountered this post code
                    PostCodeList.Add(NewPostCode);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (PostCodeList == null) //This if statement isn't necessary, but if we don't have it we have to re-read our CSV file every time someone refreshs our web form! That's extremely slow.
            {
                Load_Postcodes(@"F:\PostCode-Full_20130228.csv"); //Put in your CSV file location here! Warning: Relative file paths go from the server executable file path, NOT your web app's "bin" file path. Use a full file path if you have problems
                //                                                       The '@' denotes a string literal ('\' characters are treated as normal characters, i.e. as literal characters)
            }

        }

        protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode)
        { //Again, the search here is not what you would normally use because of how slow it is but we use it to keep things simple
          //Those of you who want a better solution can look into the SortedDictionary to use instead of a List (MSDN is very useful!)
            foreach (PostCodeInfo entry in listToCheck)
            {
                if (entry.PostCode == postCode)
                    return entry;
            }
            return null; //Return nothing if it's not in our list
        }


        protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode2)
        { //Again, the search here is not what you would normally use because of how slow it is but we use it to keep things simple
            //Those of you who want a better solution can look into the SortedDictionary to use instead of a List (MSDN is very useful!)
            foreach (PostCodeInfo entry in listToCheck)
            {
                if (entry.PostCode == postCode2)
                    return entry;
            }
            return null; //Return nothing if it's not in our list
        }





        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string PostCode = txtOriginPost.Text;
            string PostCode2 = txtDestPost.Text;
            //See if you're able to put some error checking in for the post code after you've finished the second half of prac 2!

            PostCodeInfo MatchingPostCode = Find(PostCodeList, PostCode);
            if (MatchingPostCode == null)
            {
                lblOutput.Text = "Your postcode could not be found!";
            }
            else
            {
                lblOutput.Text = string.Format("Your post code is in {0}, {1}", MatchingPostCode.Locality, MatchingPostCode.State);
            }

            PostCodeInfo MatchingPostCode2 = Find(PostCodeList, PostCode2);

            if (MatchingPostCode2 == null)
            {
                lblOutput2.Text = "Your postcode could not be found!";
            }
            else
            {
                lblOutput2.Text = string.Format("Your post code is in {0}, {1}", MatchingPostCode2.Locality, MatchingPostCode2.State);
            }

        }
    }
}
namespace-GetPost
{
公共类邮政编码信息
{
公共字符串邮政编码{get;set;}
公共字符串位置{get;set;}
公共字符串状态{get;set;}
公共字符串邮政编码2{get;set;}
公共邮政编码信息(字符串邮政编码、字符串邮政编码2、字符串位置、字符串状态)
{
邮政编码=邮政编码;
邮政编码2=邮政编码2;
地点=地点;
状态=状态;
}
}
公共部分类WebForm1:System.Web.UI.Page
{
受保护的静态列表后编码列表;
受保护的布尔包含(列表列表检查、字符串邮政编码)
{//这是一个通常不会使用的非常缓慢的搜索,但为了保持简单,我们将遍历每个列表项并检查我们的post代码
foreach(listToCheck中的PostCodeInfo条目)
如果(entry.PostCode==邮政编码)
返回true;
返回false;
}
受保护的无效加载\邮政编码(字符串CSVFileName)
{
PostCodeList=新列表();
StreamReader=null;
尝试
{
Reader=新的StreamReader(CSVFileName);
}
捕获(FileNotFoundException ex)
{
lblOutput.Text=string.Format(“错误:检查邮政编码CSV的文件路径和文件名是否正确!当前设置为:{0}',CSVFileName”);
返回;
}
Reader.ReadLine();//去掉文件中包含列名称的第一行(例如“Pcode”、“Locality”等)
while(Reader.EndOfStream==false)
{
字符串CurrentLine=Reader.ReadLine();
string[]Columns=CurrentLine.Split(新字符[]{',});
for(int i=0;i
这两个调用是相同的,这就是为什么:

protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode)
protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode2)

您有两个签名完全相同的方法:

protected PostCodeInfo Find(List<PostCodeInfo> x, string y);
pro
protected PostCodeInfo Find(List<PostCodeInfo> x, string y);
 protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode)
 protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode2)
 protected PostCodeInfo Find(List<PostCodeInfo> listToCheck, string postCode)
 protected PostCodeInfo Find2(List<PostCodeInfo> listToCheck, string postCode)