[英]Windows Phone-cannot declare instance members in a static class in C#
Hi I'm new in Windows phone development
and I do some exercises to learn how to develop. 嗨,我是
Windows phone development
新手,我做一些练习来学习如何开发。 I tried to use the ContactManager class to get device's contact and I get this error: 我尝试使用ContactManager类获取设备的联系人,但出现此错误:
cannot declare instance members in a static class 'Contact Manager'
无法在静态类“ Contact Manager”中声明实例成员
My class is not a static
,so why it still show me this error? 我的课程不是
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
}
}
}
}
Yep, it's static: public static class ContactManager
. 是的,它是静态的:
public static class ContactManager
。
Click on "C#" to view declaration: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.contacts.contactmanager.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1 单击“ 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.