Hi,
How can insert an item to Expression array? For example: some code like
Expression<Func<int, bool>>[] exprs;
Expression<Func<int, bool>> expr = i => i > 0;
exprs.Add(expr);
Thanks
Hi,
How can insert an item to Expression array? For example: some code like
Expression<Func<int, bool>>[] exprs;
Expression<Func<int, bool>> expr = i => i > 0;
exprs.Add(expr);
Thanks
If you want to use an array, you need to initialize it first:
Expression<Func<int, bool>>[] exprs = new Expression<Func<int, bool>>[arrayLength];
Expression<Func<int, bool>> expr = i => i > 0;
exprs[0] = expr;
This just just like any other array type in C#. For details on arrays, see MSDN.
If you just need a collection that can grow as needed, consider List<T>
instead:
List<Expression<Func<int, bool>>> exprs = new List<Expression<Func<int, bool>>>();
Expression<Func<int, bool>> expr = i => i > 0;
exprs.Add(expr); // This works with List<T> - you don't need the size in advance.