Hi I'm new in Windows phone development
and I do some exercises to learn how to develop. I tried to use the ContactManager class to get device's contact and I get this error:
cannot declare instance members in a static class 'Contact Manager'
My class is not a static
,so why it still show me this error?
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
.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.