this code checks if the list of counterparties contains email addresses. then in the else statement there is a chance that the email address still becomes 0. I need a piece of code that fills in the email address list when it is zero.
if (counterParty == null)
{
mailAddressesOfCounterparty = new List<Email>();
Email unKnownEmail = new Email();
unKnownEmail.EmailAddress = loopPayment.ShortNameCalypso + "@NotInCounterpartyTable.nl";
mailAddressesOfCounterparty.Add(unKnownEmail);
}
else
{
mailAddressesOfCounterparty =
emailAddress.Where(ea => ea.CounterPartyId == counterParty.Id && ea.IsOptionContract == startOfGroupPayment.OptionContract).ToList();
}
this code needs to make the email address. only don't know how to check if zero.
Email unKnownEmail = new Email();
unKnownEmail.EmailAddress = loopPayment.ShortNameCalypso + "@NotInCounterpartyTable.nl";
mailAddressesOfCounterparty.Add(unKnownEmail);
in the else i need to add a possibility to change the email address to something when it becomes zero there. the code won't let me us an if statement.
mailAddressesOfCounterparty becomes zero because something isn't added in the database yet. But that information could be missing when using this application aswell. In that case i want to create an emailaddress that will show that it couldn't be found.
If I understand the question correctly, you want to verify whether there are any addresses in the list which you've filtered in the else clause.
The linq extension method "Any()" can be used to determine whether an enumeration contains any items (there's other ways too), an example of this in use (based on your code) is:
if (counterParty == null)
{
mailAddressesOfCounterparty = new List<Email>();
Email unKnownEmail = new Email();
unKnownEmail.EmailAddress = loopPayment.ShortNameCalypso + "@NotInCounterpartyTable.nl";
mailAddressesOfCounterparty.Add(unKnownEmail);
}
else
{
mailAddressesOfCounterparty = emailAddress.Where(ea => ea.CounterPartyId == counterParty.Id && ea.IsOptionContract == startOfGroupPayment.OptionContract).ToList();
if (!mailAddressesOfCounterparty.Any())
{
Email unKnownEmail = new Email();
unKnownEmail.EmailAddress = loopPayment.ShortNameCalypso + "@NotInCounterpartyTable.nl";
mailAddressesOfCounterparty.Add(unKnownEmail);
}
}
If I understood the question correctly, in the else
branch you could introduce an initialization like the following
mailAddressesOfCounterparty = mailAddressesOfCounterparty ?? new List<Email>();
which would initialize it with a new list if it is null
. However, I don't see how mailAddressesOfCounterparty
could be null after the first statement of the else
branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With