M
mamabrowsss
Guest
I apologize if my question doesn't make sense, I'm not very technical when trying to ask questions but here goes...
I'm trying to figure out if a collection contains something. The last 'IF' statement is the part I'm having trouble with. I want demosAreDifferent to be set to 'true' if viewModel.CurrentMaster.DemoSelections does not contain what is in 'demo' but it's being set to true even when 'demo' is contained in DemoSelections. What am I doing wrong?
var demosAreDifferent = false;
if (campaign.CampaignMediaMaster?[0].DemoSelections.Count != viewModel.CurrentMaster?.DemoSelections.Count)
{
demosAreDifferent = true;
}
else
{
var demoCounter = 0;
foreach (var demo in campaign.CampaignMediaMaster?[0].DemoSelections)
{
var vmDemo = viewModel.CurrentMaster?.DemoSelections[demoCounter++].DemographicID;
if (demo.DemographicID != (int)vmDemo)
{
demosAreDifferent = true;
}
// the next IF is where I'm having the issue...
if (!viewModel.CurrentMaster.DemoSelections.Contains(demo))
{
demosAreDifferent = true;
}
}
}
Thanks in advance for any guidance you can provide!
- Joni
Continue reading...
I'm trying to figure out if a collection contains something. The last 'IF' statement is the part I'm having trouble with. I want demosAreDifferent to be set to 'true' if viewModel.CurrentMaster.DemoSelections does not contain what is in 'demo' but it's being set to true even when 'demo' is contained in DemoSelections. What am I doing wrong?
var demosAreDifferent = false;
if (campaign.CampaignMediaMaster?[0].DemoSelections.Count != viewModel.CurrentMaster?.DemoSelections.Count)
{
demosAreDifferent = true;
}
else
{
var demoCounter = 0;
foreach (var demo in campaign.CampaignMediaMaster?[0].DemoSelections)
{
var vmDemo = viewModel.CurrentMaster?.DemoSelections[demoCounter++].DemographicID;
if (demo.DemographicID != (int)vmDemo)
{
demosAreDifferent = true;
}
// the next IF is where I'm having the issue...
if (!viewModel.CurrentMaster.DemoSelections.Contains(demo))
{
demosAreDifferent = true;
}
}
}
Thanks in advance for any guidance you can provide!
- Joni
Continue reading...