158
ContravariantDelegate<string> fun3 = new ContravariantDelegate<string>(Program.Contravariant<string>);
1
// Author : Tech Point Fundamentals
2
// Website : www.techpointfunda.com
3
// YouTube : https://www.youtube.com/c/TechPointFundamentals
4
// Demo : Covariant and Contravariant in C#
5
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9
10
11
interface ICovariant<out T>
12
{
13
// T as input parameter not allowed
14
//void Add(T item);
15
//void Update(T item);
16
void Delete(int id);
17
T Get(int id);
18
IEnumerable<T> GetAll();
19
IQueryable<T> iGetAll();
20
21
// But T is allowed in Action<T> because it is a ContraVariant Delegate
22
void Acknowledge(Action<T> callback);
23
24
// Generic constraint for the interface methods not allowed.
Cached Result
Hello World