C#中以下代码段的可能值是多少? [英] What is possible value for the below snippet in C#

查看:67
本文介绍了C#中以下代码段的可能值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码和在什么情况下,Console.WriteLine()的可能输出是什么?



static void检查(输出int a,out int b )

{

a = 2;

b = 3;

Console.WriteLine(a == b);

}



我的尝试:



当我在VS中运行它时,它只是给出了错误的答案。

但这是在一个谜题中被问到所以我认为这可能是真的可能,但在特定场景中我我期待着解释

What can be the possible output of Console.WriteLine() in below code and in what scenarios?

static void Check(out int a, out int b)
{
a = 2;
b = 3;
Console.WriteLine (a == b);
}

What I have tried:

as I ran it in VS , it simply gave false as the answer.
But this was asked in a puzzle so I think there would be true possible for this but in a specific scenario that I am looking forward to have the explanation for

推荐答案

当函数调用如下时返回True



int a;

检查(out a,out a);



在所有其他情况下返回False。



这是在答案揭晓后我才知道的。 !!!
Returns True when function is called as below

int a;
Check(out a, out a);

Returns False in all other cases.

This is what I got to know after the answer was revealed. !!!


在我看来,t总是假的。



在这种方法中你总是设置为2和b为3.

之后你比较它们是否相等并且由于方法设置(a = 2,b = 3),它总是相同的。



在C#中创建并使用各种方案进行测试以确保
In my opinion t is always false.

In this method you always set a to 2 and b to 3.
After that you compare if they are equal and thanks to the method settings (a=2, b=3), it is always the same.

Create this in C# and test with various scenarios to be sure tho


我认为访调员试图通过使用OUT关键字来混淆你。在程序中,它写成a = 2和b = 3,所以它显然是假的。
I think interviewer was trying to confuse you by using OUT keyword. As in the program it is written a=2 and b=3 so it will be false obviously.


这篇关于C#中以下代码段的可能值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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