Hopefully I've just done something dumb but I get an int array and I want to assign that to a property - but even though the int array is not null, when I assign it to the property it is null. Note this is broken into several statements as I was testing that my select statement worked ok.
希望我做了一些蠢事,但我得到了一个int数组,我想把它赋值给一个属性——但即使int数组不是null,当我赋值给这个属性时,它也是空的。注意,在我测试select语句是否正常时,这被分成了几个语句。
int[] placementslist = selfSelPlacements.Select(p => p == null ? 0 : p.PlacementId).ToArray<int>();
I have tried
我有试过
UnitOfferingListCriteria.Placements = new int[placementslist.Length];
as well as just assigning
除了分配
UnitOfferingListCriteria.Placements = placementslist;
But UnitOfferingListCriteria.Placements is always null despite placementslist having 1 item.
但UnitOfferingListCriteria。尽管placement.com有一个条目,但它始终是空的。
In my class for the property
在我的课上
public int[] Placements { get; set; }
If someone could point out what I'm doing wrong - thanks!
如果有人能指出我做错了什么-谢谢!
Edit - thanks for the suggestions, been swamped with other stuff so haven't had a chance to get back to it yet.
编辑-谢谢你的建议,被其他的东西淹没了,所以还没有机会回到它。
3 个解决方案
#1
0
public int[] Placements { get; set; }
will have a default value of null.
默认值为null。
Is UnitOfferingListCriteria
a class or a class instance? It looks like you are doing something with a static property? Or are you accessing a property on a property?
UnitOfferingListCriteria是类还是类实例?看起来你在用静态属性做什么?或者你正在访问一个属性上的属性?
#2
1
This works for me
这适合我
int[] placementslist = selfSelPlacements.Select(p => p == null ? 0 : p.PlacementId).ToArray<int>();
UnitOfferingListCriteria.Placements = new int[placementslist.Length];
placementslist.CopyTo(UnitOfferingListCriteria.Placements, 0);
And the class
和类
public class UnitOfferingListCriteria
{
public static int[] Placements{ get; set; }
}
Are you doing anything different?
你有什么不同吗?
#3
0
The instance you are trying to reference in the property must not be null when you do it. This is obvious, but sometimes obvious is just much obvious.
您试图在属性中引用的实例在执行时一定不能为空。这是显而易见的,但有时显然是显而易见的。
#1
0
public int[] Placements { get; set; }
will have a default value of null.
默认值为null。
Is UnitOfferingListCriteria
a class or a class instance? It looks like you are doing something with a static property? Or are you accessing a property on a property?
UnitOfferingListCriteria是类还是类实例?看起来你在用静态属性做什么?或者你正在访问一个属性上的属性?
#2
1
This works for me
这适合我
int[] placementslist = selfSelPlacements.Select(p => p == null ? 0 : p.PlacementId).ToArray<int>();
UnitOfferingListCriteria.Placements = new int[placementslist.Length];
placementslist.CopyTo(UnitOfferingListCriteria.Placements, 0);
And the class
和类
public class UnitOfferingListCriteria
{
public static int[] Placements{ get; set; }
}
Are you doing anything different?
你有什么不同吗?
#3
0
The instance you are trying to reference in the property must not be null when you do it. This is obvious, but sometimes obvious is just much obvious.
您试图在属性中引用的实例在执行时一定不能为空。这是显而易见的,但有时显然是显而易见的。