G
Guest
Hi,
I need to initialize my class level dictionary (in .Net 2.0). I wanted to
make it inline and employ anonymous methods as I do not use this code for
anything else. Something similar to the following:
private static Dictionary<string, field> _fields = delegate()
{
Dictionary<string, field> result = new Dictionary<string, field>();
result.Add("Application", new field("Application", "AppName"));
...
return result;
};
And then I need to use the dictionary values in the rest of the declarations.
Apparently the code above does not compile with the error: "Cannot convert
anonymous method block to type
'System.Collections.Generic.Dictionary<string,GroupDates.field>' because it
is not a delegate type".
I understand that it is not - but what is the correct way to initialize a
variable with anonymous method (and is there)?
I could always create a method that would return the correct initialized
object, but would prefer not to.
Any suggestions are appreciated.
I need to initialize my class level dictionary (in .Net 2.0). I wanted to
make it inline and employ anonymous methods as I do not use this code for
anything else. Something similar to the following:
private static Dictionary<string, field> _fields = delegate()
{
Dictionary<string, field> result = new Dictionary<string, field>();
result.Add("Application", new field("Application", "AppName"));
...
return result;
};
And then I need to use the dictionary values in the rest of the declarations.
Apparently the code above does not compile with the error: "Cannot convert
anonymous method block to type
'System.Collections.Generic.Dictionary<string,GroupDates.field>' because it
is not a delegate type".
I understand that it is not - but what is the correct way to initialize a
variable with anonymous method (and is there)?
I could always create a method that would return the correct initialized
object, but would prefer not to.
Any suggestions are appreciated.