C# Visual Studio 2010 C“;已定义具有相同参数类型的成员错误。”;

C# Visual Studio 2010 C“;已定义具有相同参数类型的成员错误。”;,c#,types,parameters,member,defined,C#,Types,Parameters,Member,Defined,我在VisualStudio中遇到了一个问题,它一直说我定义了一个具有相同参数类型的成员。我是C#编程新手,我真的不知道该怎么办。以下是正在发生的错误: 错误1类型“Secret.AddPage”已定义名为 具有相同参数类型的“AddPage” 错误2类型“Secret.AddPage”已定义名为 具有相同参数类型的“PhoneApplicationPage_Loaded” 这是我迄今为止所写的代码,非常感谢您的帮助 enter code here using System; using Sy

我在VisualStudio中遇到了一个问题,它一直说我定义了一个具有相同参数类型的成员。我是C#编程新手,我真的不知道该怎么办。以下是正在发生的错误:

错误1类型“Secret.AddPage”已定义名为 具有相同参数类型的“AddPage”

错误2类型“Secret.AddPage”已定义名为 具有相同参数类型的“PhoneApplicationPage_Loaded”

这是我迄今为止所写的代码,非常感谢您的帮助

enter code here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;

namespace secret
{
public partial class AddPage : PhoneApplicationPage
{
    private string location = "";

    public AddPage()
    {
        InitializeComponent();

        GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher();
        var myPosition = myWatcher.Position;

        // Eftersom koden körs i emulatorn kan den inte få tillgång till riktiga GPS-värden
        // Därför hårdkodas koordinaterna till slottet i Gamla stan så att MSR MAPS Web Services
        //kan testas.

        double latitude = 40.717;
        double longitude = -74;

        if (!myPosition.Location.IsUnknown)
        {
            latitude = myPosition.Location.Latitude;
            longitude = myPosition.Location.Longitude;
        }

        myTerraService.TerraServiceSoapClient client = new myTerraService.TerraServiceSoapClient();

        client.ConvertLonLatPtToNearestPlaceCompleted += new EventHandler<myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs>(client_ConvertLonLatPtToNearestPlaceCompleted);

        client.ConvertLonLatPtToNearestPlaceAsync(new myTerraService.LonLatPt { Lat = latitude, Lon = longitude });
    }

    void client_ConvertLonLatPtToNearestPlaceCompleted(object sender, myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs e)
    {
        location = e.Result;

        //throw new NotImplementedException();
    }


    private void AppBar_Cancel_Click(object sender, EventArgs e)
    {
        navigateBack();
    }

    private void AppBar_Save_Click(object sender, EventArgs e)
    { // spara en ny anteckning

        if (location.Trim().Length == 0)
        {
            location = "Okänd";
        }

        navigateBack();

    }
    private void navigateBack()
    {
        NavigationService.Navigate(new Uri("/secret;component/NotesMainPage.xaml", UriKind.Relative));
    }

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        editTextBox.Focus();

    }
}
}
在此处输入代码
使用制度;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用Microsoft.Phone.Controls;
使用系统、设备、位置;
名称空间秘密
{
公共部分类AddPage:PhoneApplicationPage
{
私有字符串位置=”;
公共地址页()
{
初始化组件();
GeoCoordinateWatcher myWatcher=新的GeoCoordinateWatcher();
var myPosition=myWatcher.Position;
//我仿效科登·科尔斯在里克蒂加GPS-värden之前的做法
//Därför hårdkodas koordinaterna till Slotte i Gamla stan såatt MSR地图Web服务
//kan testas。
双纬度=40.717;
双经度=-74;
如果(!myPosition.Location.IsUnknown)
{
纬度=myPosition.Location.latitude;
经度=myPosition.Location.longitude;
}
myTerraService.TerraServiceSoapClient=新的myTerraService.TerraServiceSoapClient();
client.convertlonlatptonearestplacecompleted+=新事件处理程序(client_convertlonlatptonearestplacecompleted);
convertlonlatptonearestpeacesync(新的myTerraService.LonLatPt{Lat=纬度,Lon=经度});
}
无效客户端\u ConvertLonLatPtToNearestPlaceCompleted(对象发送方,myTerraService.ConvertLonLatPtToNearestPlaceCompleted事件参数e)
{
位置=e.结果;
//抛出新的NotImplementedException();
}
私有无效AppBar\u取消\u单击(对象发送者,事件参数e)
{
导航返回();
}
私有void AppBar_保存_单击(对象发送方,事件参数e)
{//spara en ny anteckning
if(location.Trim().Length==0)
{
location=“Okänd”;
}
导航返回();
}
私有void navigateBack()
{
NavigationService.Navigate(新Uri(“/secret;component/NotesMainPage.xaml”,UriKind.Relative));
}
已加载专用void PhoneApplicationPage_(对象发送方,路由目标)
{
editTextBox.Focus();
}
}
}

您正在创建一个分部类,因此可能在分部类的另一个源文件中定义了这些成员

您可以查看解决方案资源管理器,找到源文件并从中删除它,或者从当前的分部类中删除这些成员

你可以看到:


要搜索包含分部类的其他源文件,请右键单击类名
添加页面
,然后选择
转到定义
。您将在VisualStudio的“查找符号结果”窗口中看到多个结果

检查另一个已定义
AddPage()
构造函数或
PhoneApplicationPage\u Loaded()方法的分部类。您可以通过Ctrl+F并在解决方案中搜索方法签名来实现这一点:

public AddPage()


我最近有一个非常类似的例子,结果证明,当导入现有代码文件时,我已经导入了
obj
目录本身!

例如,此目录包含自动生成(和自动导入)的
MainWindow.g.i.cs
文件。因此,我两次有效地包含了相同的部分类定义,因此出现了“已定义”错误


这是如何帮助别人的

我有一个项目,在该项目中,我在notepad++中打开了main program.cs,进行了一些编辑,并执行了“另存为”操作,将文件复制到同一文件夹中。我后来在VisualStudio中打开了同一个项目,在尝试编译时遇到了同样的错误。我只需通过右键单击问题文件并选择“从项目中排除”,将我创建的文件从项目中排除。做了一个构建和中提琴!副本仍在文件夹中,只是未包含在生成中。

在我的例子中,这个错误的原因最终就这么简单。我在DB项目中向EDMX添加了一个新的DB表。我无意中勾选了使用方法生成类的框(但这些方法已经在项目中生成)。此后的EDMX文件包含两个名称类似的类AB.Context.tt和AB.xxx.Context.tt,并且都包含相同的方法。由于类是局部的,因此出现了上述错误


解决方案是删除意外和新添加的辅助AB.xxx.Contex.tt文件并重建项目。

是否“在此处输入代码”是其中的一部分?部分类是否有任何其他部分?
否“在此处输入代码”不是其中的一部分。默认情况下为其分部类,我真的很新,正在遵循一个教程并在我自己的应用程序中实现它,虽然我做了完全相同的事情,但我得到了这些错误?它只是显示了部分Addpage和公共Addpage,我不完全确定该怎么做,因为我在删除上或其他的?公共部分类AddPage:PhoneApplicationPage{public AddPage()我建议您在原始问题中发布这两个部分类(只需更新/编辑原始问题)。我发现另一个c#文件具有相同的名称
PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)