【发布时间】:2010-07-15 11:30:41
【问题描述】:
如果我写了会是什么输出
在 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#
编辑
if(printf("Hi"){} //will run and enter into if statement
if(printf(""){}//will enter into else condition if found.
此问题不适用于不了解 Turbo Compiler 的人
【问题讨论】:
-
你是说
if(void)在 Turbo C++ 中工作? -
这也是 C++ 中的一个错误。问题不在于它是否运行,而在于它是否编译。 C++ 和 C# 都是编译语言,而不是解释语言。所以这个问题根本没有意义。
-1来自我。 -
@sbi:你的 -1 没问题,谢谢。我没有考虑 VS C++,我明确指定了 turbo 编译器。 @Henk:是的,我的意思是一样的,但仅限于 Turbo Compiler
-
@Shantanu:抱歉,我根本不相信任何版本的 TC 都允许你编译
if(func())如果func()返回void。 -
@Shantanu:您可能想更改问题的文本:“当我使用损坏的 C++ 编译器时......”
标签: c# c++ casting void conceptual