2012-11-05 136 views
2

即時通訊在視覺工作室有問題,它一直說我已經定義了一個具有相同參數類型的成員。我新來C#編程,我真的不知道該怎麼做。這些是發生的錯誤:Visual Studio 2010 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(); 

    } 
} 
} 
+0

是'enter code here'的一部分嗎? – mcalex

+3

'partial class'是否有其他部分? –

+0

否「在此輸入代碼」不是它的一部分。它的部分類默認情況下,即時通訊真的很新,並遵循一個教程,並將其實施到我自己的應用程序,雖然我已經完全相同,我得到這些錯誤? –

回答

8

您正在創建一個部分類,因此您可能在另一個源文件中爲您的部分類定義了這些成員。

您可以查看解決方案資源管理器,找到該源文件並將其從中刪除,或者您可以從當前的部分類中刪除這些成員。

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

搜索包含部分類的其他來源的文件,右鍵單擊類名稱AddPage並選擇Go to Definition。您將在Visual Studio的查找符號結果窗口中看到多個結果。

+0

我發現另一個c#文件具有相同的名稱,但當我將它們更改爲它們各自的名稱時其他文件也更改了它的名稱?當我手動寫入它們,並且不使用選項來引用和更改名稱時,InitialiseComponents和editTextBox在當前上下文中不存在 –

2

檢查另一個部分類,其中已經定義了AddPage()構造函數或PhoneApplicationPage_Loaded()方法。您可以通過按Ctrl + ˚F實現這一目標,並尋找方法簽名解決方案:

public AddPage() 

PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) 
+0

它只是顯示了部分Addpage和公共Addpage im不完全確定要做什麼,因爲我得到了很多其他錯誤時刪除或其他?公共部分班級AddPage:PhoneApplicationPage { public AddPage() –

+0

我會建議你在原始問題中發佈兩個部分類(只需更新/編輯原始問題)。 – alan

0

我有非常類似的東西最近,和導入時,原來,現有的代碼文件我已經導入obj目錄本身! visual studio screen shot

此目錄包含例如自動生成(並自動導入)MainWindow.g.i.cs文件。所以我有效地包含了相同的部分類定義兩次,因此「已定義」的錯誤。

這對別人有什麼幫助!

相關問題