objectinitalizer

C# 3.0 - Object initializer

Hello, I'm having a little problem and I don't see why, it's easy to go around it, but still I want to understand. I have the following class : public class AccountStatement : IAccountStatement { public IList<IAccountStatementCharge> StatementCharges { get; set; } public AccountStatement() { new AccountStatemen...

Using an Anonymous method to populate a property in an object initializer

Assuming sr is an IEnumerable, I want to use code like this to do an inline calculation using two of the items from sr.Lines(). The problem is that the lambda is of type "lambda expression" and not a Decimal, which shares is expecting. Is there any way to do this type of inline method in an object initializer? var trades = from line...

Adding a onclick event to a code generated html element via object initializer

I would like to be able to add a click event to a entity generated in the code behind. Currently I'm doing it like this: TableRow row = new TableRow(); row.Attributes.Add("onclick", "clickFunction(this)"); Is there a way to do this using the object initializer? I am doing a lot of control creation/initialization and if it matched ...