【问题标题】:Windows Phone-cannot declare instance members in a static class in C#Windows Phone - 不能在 C# 中的静态类中声明实例成员
【发布时间】: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


【解决方案1】:

【讨论】:

  • 是的,我也检查了这个,那么我如何使用联系人管理器获取设备的联系人?
  • 你知道或至少了解 C++ CLI 吗?
  • 如果是这样,这里是一个用法示例:code.msdn.microsoft.com/windowsapps/…
  • 您的示例显示了如何添加联系人,我尝试获取所有联系人
  • 您可以做的是使用 JustDecompile 来了解所涉及的 .NET 程序集的源代码,并可能了解 ContactManager 的工作原理。我个人从来没有使用过 ContactManager,所以我现在不能告诉你如何使用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-08
  • 1970-01-01
  • 2016-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多