C#将按位运算符作为参数传递 [英] C# Pass bitwise operator as parameter

查看:59
本文介绍了C#将按位运算符作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将按位运算符作为参数传递给我的方法?我读过一些文章,描述了如何将例如等于运算符作为参数传递,但是他们以某种方式实现了该参数,并在此之后通过委托将该参数传递给了它.就我而言,我不确定如何实现按位运算符.

How can I pass a bitwise operator as a parameter to my method? I've read some articles that describes how to pass for example equality operator as a parameter however they implement it in some way and after this pass it with a delegate. In my case I'm not sure how to implement the bitwise operator.

推荐答案

您可以使用Func<>

You can use Func<>

int MyFunc(int input1, int input2, Func<int, int, int> bitOp)
{
    return bitOp(input1, input2);
}

像这样使用

Console.WriteLine(MyFunc(1, 2, (a, b) => a | b));

输出"3"

这篇关于C#将按位运算符作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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