Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C#, can you put an Or in an "where" interface constraint?

if i have this code:

public interface IJobHelper
{
    List<T> FilterwithinOrg<T>(IEnumerable<T> entities) where T : IFilterable;
}

is there anything that support doing something like this:

public interface IJobHelper
{
    List<T> FilterwithinOrg<T>(IEnumerable<T> entities) where T : IFilterable or ISemiFilterable
}

so it will accept anything that supports one of two interfaces. I am basically trying to create an overload.

like image 359
leora Avatar asked Apr 22 '13 03:04

leora


People also ask

What does << mean in C?

<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .

What does %d do in C?

In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.

Why is && used in C?

The logical AND operator is represented as the '&&' double ampersand symbol. It checks the condition of two or more operands by combining in an expression, and if all the conditions are true, the logical AND operator returns the Boolean value true or 1. Else it returns false or 0.


1 Answers

As far as I know, you can use AND logic not OR.

AND (in this case, T must be child of IFilterable and ISemiFilterable)

public interface IJobHelper
{
    List<T> FilterwithinOrg<T>(IEnumerable<T> entities) where T : IFilterable, ISemiFilterable
}
like image 134
Vano Maisuradze Avatar answered Oct 03 '22 15:10

Vano Maisuradze