c#相当于声明 [英] c# equivalent of statement

查看:89
本文介绍了c#相当于声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下代码是用C ++编写的。什么是C#等效代码。



Hi,

Following code is in C++. What would be C# Equivalent Code for this.

int lGpiValue = 512;
int sensor=3;

if( lGpiValue & (1<<sensor))  // What will be in c#
return 1;





请帮助。



Please help.

推荐答案

在c#中你需要在if语句中使用一个显式的布尔表达式。

所以你需要比较 lGpiValue&的结果。 (1< <传感器)带有值。

例如:

In c# you need an explicit boolean expression in an if-statement.
So you need to compare the result of lGpiValue & (1 << sensor) with a value.
For example:
int lGpiValue = 512;
int sensor = 3;

if ((lGpiValue & (1 << sensor)) != 0) // The exact comparison is for the OP to decide
    return 1;

// Alternative comparison
if (Convert.ToBoolean(lGpiValue & (1 << sensor)))
    return 1;


这篇关于c#相当于声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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