Reputation: 4459
I saw this article on msdn with the example http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
So i decided to give it a shot and try this out in my wpf application:
Dictionary<string, string> Dictionarycheck =
new Dictionary<string, string>();
Dictionarycheck.Add("demo1");
Why this won't work? I get the error: Invalid token '(' in class, struct, or interface member declaration
Upvotes: 0
Views: 605
Reputation: 3844
You are probably writing the code outside of a method (like I just did to test it). Further, Dictionary.Add has two arguments.
Upvotes: 1
Reputation: 2059
Dictionary(TKey, TValue)
So its Dictionarycheck.Add("Key", "Value");
Upvotes: 1
Reputation: 1500065
Two problems:
In other words, you've probably got something like this:
public class Test
{
Dictionary<string, string> Dictionarycheck =
new Dictionary<string, string>();
Dictionarycheck.Add("demo1");
}
when it should be something like this:
public class Test
{
public void DemoMethod()
{
Dictionary<string, string> dictionaryCheck =
new Dictionary<string, string>();
dictionaryCheck.Add("demo1", "value1");
}
}
(I've adjusted the name of the variable for convention, too.)
Upvotes: 5