Telegram Group & Telegram Channel
Что выведет следующий код на C#?


using System;

class Program {
static void Main() {
int a = 1000;
int b = 1000;

object x = a;
object y = b;

Console.WriteLine(x == y); // #1
Console.WriteLine(x.Equals(y)); // #2
}
}


🔢 Варианты ответа:

A)

True


B)

False


C)

True


D)

False


Правильный ответ: C

💡 Почему?

-
x и y — boxed значения типа int, то есть ссылки на два разных объекта в куче.
-
x == y сравнивает ссылки, а не значения → False.
-
x.Equals(y) вызывает метод Equals для int, который сравнивает значения → True.

📌 Подвох — в различии
== и .Equals() при использовании упакованных типов.

@csharp_ci



tg-me.com/csharp_ci/1336
Create:
Last Update:

Что выведет следующий код на C#?


using System;

class Program {
static void Main() {
int a = 1000;
int b = 1000;

object x = a;
object y = b;

Console.WriteLine(x == y); // #1
Console.WriteLine(x.Equals(y)); // #2
}
}


🔢 Варианты ответа:

A)

True


B)

False


C)

True


D)

False


Правильный ответ: C

💡 Почему?

-
x и y — boxed значения типа int, то есть ссылки на два разных объекта в куче.
-
x == y сравнивает ссылки, а не значения → False.
-
x.Equals(y) вызывает метод Equals для int, который сравнивает значения → True.

📌 Подвох — в различии
== и .Equals() при использовании упакованных типов.

@csharp_ci

BY C# (C Sharp) programming


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/csharp_ci/1336

View MORE
Open in Telegram


C C Sharp programming Telegram | DID YOU KNOW?

Date: |

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

In many cases, the content resembled that of the marketplaces found on the dark web, a group of hidden websites that are popular among hackers and accessed using specific anonymising software.“We have recently been witnessing a 100 per cent-plus rise in Telegram usage by cybercriminals,” said Tal Samra, cyber threat analyst at Cyberint.The rise in nefarious activity comes as users flocked to the encrypted chat app earlier this year after changes to the privacy policy of Facebook-owned rival WhatsApp prompted many to seek out alternatives.C C Sharp programming from ca


Telegram C# (C Sharp) programming
FROM USA