【发布时间】:2017-06-02 11:01:31
【问题描述】:
我有许多具有不同参数的类似方法。我试图找到一个好的和简单的重构解决方案,但没有结果。我可以使用参数对象,但我认为我需要创建另一个辅助类,它会使一切变得更复杂和更慢。
void Foo(ref int test2)
{
Goo(test2);
}
void Foo(ref long test2)
{
Goo(test2);
}
void Foo(ref double test2)
{
Goo(test2);
}
void Foo(ref string test2)
{
if (!test2.IsNull())
test2 = "sth";
Goo(test2);
}
【问题讨论】:
-
您在寻找泛型吗?
void Foo<T>(ref T test2) -
如果你能提供一个更复杂的例子会有所帮助。我们不知道
Goo做了什么,也不知道为什么您的前三个方法接受ref参数,尽管没有更改它们。
标签: c# methods parameters