如何把这两句vb.net翻译成c#?

taotao1130 2005-08-03 03:33:53
Dim fi As New FileInfo(strPath)
If (fi.Attributes And FileAttributes.ReadOnly) <> 0 Then
fi.Attributes = fi.Attributes Xor FileAttributes.ReadOnly
End If
...全文
150 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
greystar 2005-08-04
  • 打赏
  • 举报
回复
If ((fi.Attributes & FileAttributes.ReadOnly) != 0 )
{
fi.Attributes = fi.Attributes | FileAttributes.ReadOnly;

}
taotao1130 2005-08-03
  • 打赏
  • 举报
回复
没人知道?
taotao1130 2005-08-03
  • 打赏
  • 举报
回复
1.
If ((fi.Attributes && FileAttributes.ReadOnly)!= 0)
这样不行,提示:
运算符“&&”无法应用于“System.IO.FileAttributes”和“System.IO.FileAttributes”类型的操作数

2.
fi.Attributes = fi.Attributes Xor FileAttributes.ReadOnly中的Xor怎么翻译过来啊?
greystar 2005-08-03
  • 打赏
  • 举报
回复
fi.Attributes = fi.Attributes | FileAttributes.ReadOnly;
kingkoo 2005-08-03
  • 打赏
  • 举报
回复
FileInfo fi=New FileInfo(strPath);

If ((fi.Attributes && FileAttributes.ReadOnly)!= 0)
{
fi.Attributes = (fi.Attributes ^= FileAttributes.ReadOnly);
{
hope_xt 2005-08-03
  • 打赏
  • 举报
回复
FileInfo fi = new FileInfo(strPath);
if(!(fi.Attributes && FileAttributes.ReadOnly))
fi.Attributes = fi.Attributes ^ FileAttributes.ReadOnly
conan1211 2005-08-03
  • 打赏
  • 举报
回复
下面这一句好象有点问题
fi.Attributes = fi.Attributes Xor FileAttributes.ReadOnly

Xor 应该是or吧,如果是or的话那译成C#就是

FileInfo fi = New FileInfo(strPath);
If (fi.Attributes && FileAttributes.ReadOnly != 0 )
{
fi.Attributes = fi.Attributes || FileAttributes.ReadOnly;
}

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧