簡體   English   中英

Windows Phone無法在C#中的靜態類中聲明實例成員

[英]Windows Phone-cannot declare instance members in a static class in C#

嗨,我是Windows phone development新手,我做一些練習來學習如何開發。 我嘗試使用ContactManager類獲取設備的聯系人,但出現此錯誤:

無法在靜態類“ Contact Manager”中聲明實例成員

我的課程不是static課程,為什么它仍然顯示此錯誤?

    using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Contacts;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace App2
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            mytextblock.Text = "Hi";
        }
        public void GetContacts()
        {
            ContactManager theContactManager = new ContactManager();
            foreach (Contact theContact in theContactManager.GetContactCollection())
            {
                string theLine = theContact.Names[0].FormattedName;
                foreach (PhoneNumber theNumber in theContact.PhoneNumbers)
                    theLine += "\t" + theNumber.ToString();
                listBox1.Items.Add(theLine);
                //Console.WriteLine(theLine); //Uncomment this if on console
            }
        }
    }
}

是的,它是靜態的: public static class ContactManager

單擊“ C#”以查看聲明: https : //msdn.microsoft.com/zh-cn/library/windows/apps/windows.applicationmodel.contacts.contactmanager.aspx?cs-save-lang=1&cs-lang=csharp #code-snippet-1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM