spud
spud

Reputation: 251

Using a string value as an attribute

I want to loop through a collection of string values and insert them as attributes. Something like this:

foreach (var result in results)
{
    var one = result.GetStuff();
    var two = result.Find(one);
    foreach (var user in users)
    {
        one.Properties["something"].Value = two.something;
    }
}

'users' is a collection of string values. Where you see "something" (two places), I want to be using a string value from 'users'. How can I do this?

Upvotes: 2

Views: 146

Answers (2)

Oded
Oded

Reputation: 499022

Looks like you are looking for a Dictionary.

If you set the key type to a string type, this will allow you to do as your code example, though the value types need to belong to one type.

See this page for information on how to use dictionaries in .NET (thanks @Filip Ekberg).

Upvotes: 3

Filip Ekberg
Filip Ekberg

Reputation: 36287

one.Properties[user.SomeStringValue]

Upvotes: 0

Related Questions