您好我是Windows phone development
的新人,我会做一些练习来学习如何发展。
我尝试使用ContactManager类来获取设备的联系,我收到了这个错误:
无法在静态类'联系人管理器'
中声明实例成员
我的班级不是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
}
}
}
}
答案 0 :(得分:0)
是的,它是静态的:public static class ContactManager
。
点击&#34; C#&#34;查看声明: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.contacts.contactmanager.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1