当前位置:编程学习 > C#/ASP.NET >>

将此VB.NET代码翻译为C#的问题

VB.net: Dim commentPos,newLinePos,quoteCount As Integer If (newLinePos >= commentPos AndAlso quoteCount Mod 2 = 0) Then 我将它改为: int commentPos,newLinePos,quoteCount; if (newLinePos >= commentPos && quoteCount % 2 = 0) //运算符 "&&" 无法应用于 "bool" 和 "int" 类型的操作数 小弟新手,请教应该怎么改才对啊?
追问:还是错:
1.赋值号左边必须是变量、属性或索引器
2.运算符 "&&" 无法应用于 "bool" 和 "int" 类型的操作数
答案:if (   (newLinePos >= commentPos)      &&      (quoteCount % 2 = 0)      )
运算符有优先级的,这个可以查一下C#的基本语法
其他:if (newLinePos >= commentPos && quoteCount % 2 == 0) 
{
} c语言中,一个等号是赋值,连续两个等号才是表达式比较
if ((newLinePos >= commentPos && quoteCount % 2 == 0)) 

上一个:vb.net什么方法获取数组元素的索引与string数组排序
下一个:如何让VB.NET执行循环时执行其他东西呢?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,