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

问题描述 投票:3回答:4

具有在Visual Studio中问题即时它保持说我已经定义与相同参数类型的部件。进出口新的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();

    }
}
}
c# types parameters member defined
4个回答
12
投票

您正在创建一个部分类,所以你可能在你的部分类另一个源文件中定义这些成员。

你可以看看在Solution Explorer中,找到源文件,要么从那里删除它,或者你可以从你的当前部分类中删除这些成员。

您可能会看到:Partial Classes and Methods (C# Programming Guide)

要搜索包含部分类的其他来源的文件,右键单击类名称AddPage并选择Go to Definition。你会看到在查找符号结果窗口中的多个结果在Visual Studio。


2
投票

检查中,您已经定义的AddPage()构造函数或方法PhoneApplicationPage_Loaded()另一部分类。您可以按Ctrl + F实现这一目标,并寻找方法签名解决方案:

public AddPage()

PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)

0
投票

我有非常类似的东西最近,它原来是导入现有的代码文件时,我已经进口obj目录本身!

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

这怎么帮助别人!


0
投票

我曾在那里我在记事本中打开++主要Program.cs的一个项目,做了一些修改,并做了“另存为”,使文件的副本在同一个文件夹中。后来我打开Visual Studio中的同一个项目,并在编译的时候得到这个同样的错误。我不得不排除我从右键单击问题文件,并选择使该项目的副本创建的文件“从项目中排除”。做了构建和中提琴!副本还只是没有被包括在生成的文件夹中。 screen shot of excluded files

© www.soinside.com 2019 - 2024. All rights reserved.