【发布时间】:2016-06-15 00:14:44
【问题描述】:
您好,我是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
}
}
}
}
【问题讨论】:
-
至少告诉我们这发生在哪一行。发布完整的错误消息。
-
在这一行:ContactManager theContactManager = new ContactManager();
-
不太可能。同样,发布(复制/粘贴)完整的错误消息。
标签: c# static windows-phone contacts