具有在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();
}
}
}
您正在创建一个部分类,所以你可能在你的部分类另一个源文件中定义这些成员。
你可以看看在Solution Explorer中,找到源文件,要么从那里删除它,或者你可以从你的当前部分类中删除这些成员。
您可能会看到:Partial Classes and Methods (C# Programming Guide)
要搜索包含部分类的其他来源的文件,右键单击类名称AddPage
并选择Go to Definition
。你会看到在查找符号结果窗口中的多个结果在Visual Studio。
检查中,您已经定义的AddPage()
构造函数或方法PhoneApplicationPage_Loaded()
另一部分类。您可以按Ctrl + F实现这一目标,并寻找方法签名解决方案:
public AddPage()
和
PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
我有非常类似的东西最近,它原来是导入现有的代码文件时,我已经进口obj
目录本身!
此目录中包含,例如,自动生成的(和自动导入)MainWindow.g.i.cs
文件。所以我有效,包括相同的部分类定义的两倍,因此“已定义”的错误。
这怎么帮助别人!