Skip to content
Discussion options

You must be logged in to vote

This compiles:

public interface A { }
public interface B { }
public interface C<T> { }

public interface D : A, B { }

public class Source<T> : A, B, C<T> { }
public class Target<T> where T : A, B { 
    readonly T _value;
    public Target(T value) {
        _value = value;
    }
    public void DoWork() {}
}

public static class TargetCreator {
    public static Target<T> Create<T>(T value) where T : A, B => new Target<T>(value);
}

public class M {
    static void Main()
    {
        Source<int> t = new();
        if (t is D d) // false
        {
            TargetCreator.Create(d).DoWork();
        }
        else if (t is A && t is B) // true
        {
            TargetCreator.Create(t

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@maxkoshevoi
Comment options

@BreyerW
Comment options

Comment options

You must be logged in to vote
3 replies
@maxkoshevoi
Comment options

@bbarry
Comment options

@BreyerW
Comment options

Answer selected by maxkoshevoi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants