在C#中为函数名称创建别名 [英] creating an alias for a function name in C#

查看:578
本文介绍了在C#中为函数名称创建别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为C#中的函数名称创建别名。

I want to create an alias for a funcion name in C#.

除了函数重载外,还有其他方法吗?

Is there any way but function overloading?

public class Test
{
    public void A()
    {
        ...
    }
}

我想叫B代替下面的A。

I want to call B replace A same below.

var test = new Test();
test.B();


推荐答案

您可以使用扩展方法

public static class Extensions 
{
    public static void B(this Test t)
    {
       t.A();
    }
}

但这不是别名。它是一个包装。

But it is not an alias. It is a wrapper.

编辑

ps:我同意您的评论者如果我们了解您真正想做的事情,如果我们了解您要解决的问题,我们将能够给出更好的答案。

EDIT
ps: I agree with the commenters on your question that we'd be able to give better answers if we knew what you really wanted to do, if we understood the problem you're trying to solve.

我真的不知道产生上述扩展方法的意义。

I don't really see the point of producing the above extension method.

这篇关于在C#中为函数名称创建别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆