Created
June 20, 2023 11:07
-
-
Save Konard/8b29a59f6162551e1da2c537832d9c23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IProcessor<in T> | |
{ | |
void Process(T input); | |
} | |
public class StringProcessor : IProcessor<string> | |
{ | |
public void Process(string input) | |
{ | |
Console.WriteLine($"Processing string: {input}"); | |
} | |
} | |
public class ObjectProcessor : IProcessor<object> | |
{ | |
public void Process(object input) | |
{ | |
Console.WriteLine($"Processing object: {input}"); | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
IProcessor<object> objectProcessor = new ObjectProcessor(); | |
IProcessor<string> stringProcessor = new StringProcessor(); | |
Process("Hello world!", stringProcessor); // Processing string: Hello world! | |
Process("Hello world!", objectProcessor); // Processing object: Hello world! | |
} | |
static void Process<T>(T input, IProcessor<T> processor) | |
{ | |
processor.Process(input); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment