3

I have this:

void SaveMultiple(Dictionary<string, decimal> updates)
{
ColumnSet cs = new ColumnSet();
cs.Attributes = new string[] { "att1", "att2", "add3" };
}

My attributes array needs to be all the string values of the dictionary.

How can I do that?

Thanks

1
  • Just as a note, in a Dictionary<string, int>, the strings are called the key (left hand side), the ints are called the value (right hand side). Important distinction to make, as keys are forcibly unique, whereas values are not. Commented May 27, 2015 at 9:37

4 Answers 4

4

You mean the keys of this dictionary? Then updates.Keys.ToArray() will give them to you.

Sign up to request clarification or add additional context in comments.

Comments

3
cs.Attributes = updates.Keys.ToArray();

Comments

0
cs.Attributes = updates.Values.ToArray();

if you want the Values or

cs.Attributes = updates.Keys.ToArray();

if you want the Keys (most likely as shown in your code snippet)

1 Comment

At least convert them to string before arrayzing them :-)
0
void SaveMultiple(Dictionary<string,decimal> updates) 
{
  ColumnSet cs=new ColumnSet();
  cs.Attributes=updates.Keys.ToArray();
}

1 Comment

While this post may answer the question, it is still a good idea to add some explanation and, possibly, some links to the relevant documentation. Answers with good explanations and references are usually more useful both to the current OP and to the future visitors. Full detailed answers are also more likely to attract positive votes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.