Is it possible to make the DoSomething
methods a single generic method?
https://dotnetfiddle.net/PXAiUV
I was thinking something like:
//I was thinking
//DoSomethingAny(c1.Method1, "an_id");
Here's the code
using System;
public class Program
{
static MyClass c1;
public static void Main()
{
c1 = new MyClass();
Console.WriteLine("Hello World");
DoSomething1("Test1");
DoSomething2("Test2");
DoSomething3("Test3");
//I was thinking
//DoSomethingAny(c1.Method1, "an_id");
}
static int DoSomething1(string id)
{
//much more code above, but identical in all methods
var x = c1.Method1(id);
//much more code below, but identical in all methods
return x;
}
static int DoSomething2(string id)
{
var x = c1.Method2(id);
return x;
}
static int DoSomething3(string id)
{
var x = c1.Method3(id);
return x;
}
}
public class MyClass
{
public int Method1(string id)
{
Console.WriteLine("Method 1 Do Work");
return 1;
}
public int Method2(string id)
{
Console.WriteLine("Method 2 Do Work");
return 1;
}
public int Method3(string id)
{
Console.WriteLine("Method 3 Do Work");
return 1;
}
}