Sha*_*pta -2 c# c++ casting conceptual void
如果我写的话会有什么输出
在C++ if(5)中执行没有任何问题但在C#中不会以相同的方式运行它.
if(func()){} //in C# it doesn't runs Why how does C# treats void and how in Turbo C++
void func()
{
return;
}
if(null==null){}//runs in C#
Run Code Online (Sandbox Code Playgroud)
编辑
if(printf("Hi"){} //will run and enter into if statement
if(printf(""){}//will enter into else condition if found.
Run Code Online (Sandbox Code Playgroud)
本课题不适用于那些不了解Turbo Compiler的人
在C#中,if语句中的条件类型必须可以隐式转换为bool.这减少了各种情况下的错误,基本上是一件好事.它会阻止这样的事情编译:
int x = ...;
if (x = 10) // Valid in C / C++, not in C#
Run Code Online (Sandbox Code Playgroud)
即使在C和C++中,如果你有一个合理的警告级别,一个不错的编译器会在上面的行上警告你.
如果该void版本在C++中工作,我会感到惊讶......
| 归档时间: |
|
| 查看次数: |
641 次 |
| 最近记录: |