I have this function:
public bool IsValidProduct(int productTypeId)
{
bool isValid = false;
if (productTypeId == 10 ||
productTypeId == 11 ||
productTypeId == 12)
{
isValid = true;
}
return isValid;
}
but I'm wondering if there's an easier way to write it, such as:
public bool IsValidProduct(int productTypeId)
{
bool isValid = false;
if (productTypeId.In(10,11,12))
{
isValid = true;
}
return isValid;
}
I know I could write an extension method to handle this, I'm just curious if there's already something out there or if there's a better way to write it.
An alternative for IN and EXISTS is an INNER JOIN, while a LEFT OUTER JOIN with a WHERE clause checking for NULL values can be used as an alternative for NOT IN and NOT EXISTS.
We have compiled a list of solutions that reviewers voted as the best overall alternatives and competitors to Microsoft SQL Server, including Teradata Vantage, MySQL, Oracle Database, and IBM Db2.
SQL Server 2014 and SQL Server 2012 use . Net Framework 3.5 SP1, which is supported till 2029, so this retirement doesn't impact them.
C# can execute 'SQL' select command against the database. The 'SQL' statement can be used to fetch data from a specific table in the database. Inserting data into the database – C# can also be used to insert records into the database.
new [] {10, 11, 12}.Contains(productTypeId)
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