M
Mark Rae
Hi,
This is just for my own interest - I don't actually want to do it, I'm just
curious to know if it's possible...
Say we have the following method which accepts a List<string>...
private void MyMethod(List<string> plstMyList)
{
...
}
We could make a call to MyMethod like this:
List<string> lstMyList = new List<string>();
lstMyList.Add("This is a string");
MyMethod(lstMyList);
However, although it might not be particularly elegant, we could also do the
following:
MyMethod(new List<string>(new string[] { "This is a string" });
This made me wonder if it would be possible to pass a Dictionary<string,
string> variable in the same way e.g.
private void MyMethod(Dictionary<string> pdicMyDictionary)
{
...
}
Dictionary<string, string> dicMyDictionary = new Dictionary<string,
string>();
dicMyDictionary.Add("This is a key", "This is a value");
MyMethod(dicMyDictionary);
Could we also do something like MyMethod(new Dictionary<string,
string>(...................);
This is just for my own interest - I don't actually want to do it, I'm just
curious to know if it's possible...
Say we have the following method which accepts a List<string>...
private void MyMethod(List<string> plstMyList)
{
...
}
We could make a call to MyMethod like this:
List<string> lstMyList = new List<string>();
lstMyList.Add("This is a string");
MyMethod(lstMyList);
However, although it might not be particularly elegant, we could also do the
following:
MyMethod(new List<string>(new string[] { "This is a string" });
This made me wonder if it would be possible to pass a Dictionary<string,
string> variable in the same way e.g.
private void MyMethod(Dictionary<string> pdicMyDictionary)
{
...
}
Dictionary<string, string> dicMyDictionary = new Dictionary<string,
string>();
dicMyDictionary.Add("This is a key", "This is a value");
MyMethod(dicMyDictionary);
Could we also do something like MyMethod(new Dictionary<string,
string>(...................);