3

I call a stored procedure from my code and it returns a

 IEnumerable<dynamic> data 

with 3 properties

I would like to be able to modify one of a value of the data var for example

data[2].ID = 6687687

Do you know how to do this please?

2 Answers 2

2

You can use the following code:

var lItem = data.ElementAt(2);
lItem.ID = 6687687;

However note, that this can have a bad runtime performance when used to access many different indexes and the IEnumerable has no "simple" list object as a basis.

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

Comments

2

You can access individual elements by using the ElementAt method like this:

data.ElementAt(2).ID = 6687687;

However, this is not efficient since it will iterate through the enumerable until it reaches the required index. And sometimes the enumerable that you get will execute some query every time your enumerate it. This means that you will get new objects every time you enumerate it (e.g. via ElementAt).

A better way is to convert the enumerable to a list like this:

var list = data.ToList();

And then access the elements by index like this:

list[2].ID = 6687687;

4 Comments

thanks for answer! but it displays trigger error that informs me that the number of args is uncorrect for calling méthod 'System.Object SetValue(System.String, System.Object, Boolean)
Are you sure that the underlying type supports setting the ID property as an integer?
and I would like to be able to change value of a property wathever the type of the property
Can you provide more information about the underlying type?

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.