C# Windows Phone无法在C中的静态类中声明实例成员#

C# Windows Phone无法在C中的静态类中声明实例成员#,c#,static,windows-phone,contacts,C#,Static,Windows Phone,Contacts,嗨,我是Windows phone development的新手,我做了一些练习来学习如何开发。 我试图使用ContactManager类获取设备的联系人,但出现以下错误: 无法在静态类“联系人管理器”中声明实例成员 我的类不是一个静态的,那么为什么它仍然向我显示这个错误呢 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Int

嗨,我是Windows phone development的新手,我做了一些练习来学习如何开发。 我试图使用ContactManager类获取设备的联系人,但出现以下错误:

无法在静态类“联系人管理器”中声明实例成员

我的类不是一个
静态的
,那么为什么它仍然向我显示这个错误呢

    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
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用System.Runtime.InteropServices.WindowsRuntime;
使用Windows.ApplicationModel.Contacts;
使用Windows基金会;
使用Windows。
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Controls.Primitives;
使用Windows.UI.Xaml.Data;
使用Windows.UI.Xaml.Input;
使用Windows.UI.Xaml.Media;
使用Windows.UI.Xaml.Navigation;
//空白页项模板被记录在http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
名称空间App2
{
/// 
///可以单独使用或在框架内导航到的空页。
/// 
公共密封部分类主页面:第页
{
公共主页()
{
this.InitializeComponent();
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
mytextblock.Text=“Hi”;
}
公共联系人()
{
ContactManager ContactManager=新建ContactManager();
foreach(联系ContactManager.GetContactCollection()中的联系人)
{
字符串theLine=contact.Names[0]。格式化名称;
foreach(电话号码联系人中的号码。电话号码)
该行+=“\t”+编号.ToString();
列表框1.Items.Add(该行);
//Console.WriteLine(theLine);//如果在控制台上,则取消对此的注释
}
}
}
}

是的,它是静态的:
公共静态类ContactManager

点击“C#”查看声明:

至少告诉我们这是在哪一行发生的。发布完整的错误消息。在这一行:ContactManager ContactManager=new ContactManager();不大可能发生的同样,POST(复制/粘贴)完全错误消息。是的,我也检查了,所以我如何使用联系管理器来获取设备的联系人?你知道或者至少理解C++ CLI吗?如果是这样,这里有一个使用示例:你的例子展示了如何添加一个联系人,我尝试获取所有Contacts,您可以使用JustDecompile查看相关.NET程序集的源代码,并了解ContactManager的工作原理。我个人从未使用过ContactManager,这就是为什么我现在不能告诉你如何使用它。