c#之.net 版本问题_C#和.NET棘手的问题

本文提出了一系列关于C#和.NET的有趣问题,涵盖了从基本语法到高级特性,包括类型转换、数学运算、异步编程、数据库安全及.NET平台的各种细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c#之.net 版本问题

I have collected some most interesting and not well-known questions from the web. And also based on interesting books, articles and videos I have seen, I have wrote some of questions myself.

我从网络上收集了一些最有趣且不为人所知的问题。 而且,根据我所看到的有趣的书籍,文章和视频,我自己写了一些问题。

I want propose you to guess right answer.

我想建议您猜测正确的答案。

1. What would be displayed? (if something would be displayed at all)

1.将显示什么? (如果将完全显示某些内容)

string nullString = (string)null;
Console.WriteLine (nullString is string);

2. What would be displayed on the screen in .NET console application?

2. .NET控制台应用程序的屏幕上将显示什么?

Console.WriteLine (Math.Round(1.5));
Console.WriteLine (Math.Round(2.5));

回答 (Answer)

3. What would be the result of

3.会有什么结果

static void Main(string[] args)
{
    float f = Sum(0.1f, 0.2f);
    float g = Sum(0.1f, 0.2f);
    Console.WriteLine(f == g);
}

static float Sum(float f1, float f2)
{
    return f1 + f2;
}

a) True

a)正确

b) False

b)错误

c) Exception would be thrown

c)将引发异常

d) That depend (could be either true or false)

d)依赖(可以为真或为假)

回答 (Answer)

When running normally, the JIT can store the result of the sum more accurately than a float can really represent — it can use the default x86 80-bit representation, for instance, for the sum itself, the return value, and the local variable.

正常运行时,JIT可以比浮点数实际表示的结果更准确地存储和的结果-例如,它可以使用默认的x86 80位表示形式来表示和本身,返回值和局部变量。

Credits:

学分:

Binary floating point and .NET 二进制浮点和.NET

4. What would be the result of

4.的结果是什么

float price = 4.99F;
int quantity = 17;
float total = price * quantity;
Console.WriteLine("The total price is ${0}.", total);

a) The total price is $85

a)总价格为$ 85

b) The total price is $84.83

b)总价格为$ 84.83

c) The total price is $84

c)总价为$ 84

d) The total price is $84.82999

d)总价格为$ 84.82999

5. What is the right way to store passwords in database? Choose one or multiple correct answers

5.在数据库中存储密码的正确方法是什么? 选择一个或多个正确答案

a) In plain text

a)纯文本

b) Encrypted with DES

b)用DES加密

c) Encrypted with AES

c)用AES加密

d) Hashed with MD5

d)与MD5混战

e) Hashed with SHA512

e)与SHA512混为一谈

回答 (Answer)

Don’t use MD5 anymore

不再使用MD5

By the way it is also possible to use keyed hashing algorithms: HMACSHA1 or MACTripleDES

顺便说一句,也可以使用键控哈希算法:HMACSHA1或MACTripleDES

6. In between different .NET technologies there is a lot of timers. Which one timer does not exist?

6.在不同的.NET技术之间,有很多计时器。 哪一个计时器不存在?

a) Timer from System.Windows.Forms

a)来自System.Windows.Forms的计时器

b) DispatchTimer from System.Windows.Threading

b)来自System.Windows.Threading的DispatchTimer

c) DispatchTimer from Windows.UI.XAML

c)Windows.UI.XAML中的DispatchTimer

d) Timer from System.Timers

d)来自System.Timers的计时器

e) Timer from System.Windows.Threading.Timers

e)来自System.Windows.Threading.Timers的计时器

f) Timer from System.Threading

f)来自System.Threading的计时器

回答 (Answer)

Credits: CLR via C# Jeffrey Richter

鸣谢:通过C#进行的CLR Jeffrey Richter

7. Which one .NET REPL does not exists?

7.哪一个.NET REPL不存在?

a) dotnetfiddle.net

a)dotnetfiddle.net

b) repl.it/languages/csharp

b)repl.it/语言/ csharp

c) csharpcompiler.net

c)csharpcompiler.net

d) dotnet.microsoft.com/platform/try-dotnet

d)dotnet.microsoft.com/platform/try-dotnet

e) csharppad.com

e)csharppad.com

回答 (Answer)

8. If you want to set a type long for a number in C# you can add at the end letter L or l. For example:

8.如果要在C#中为数字设置长类型,则可以在末尾添加字母L或l。 例如:

var l = 138l;

With which letter it is possible to mark a decimal type?

可以用哪个字母标记十进制类型?

a) C or c

a)C或c

b) D or d

b)D或d

c) M or m

c)M或m

d) E or e

d)E或e

回答 (Answer)

9. What will display on the screen console application that will contain next code:

9.屏幕控制台应用程序上将显示的内容将包含以下代码:

class Program
    {
         static Program()
        {
            Console.WriteLine("Static constructor");
        }

         public Program()
        {
            Console.WriteLine("Constructor");
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Main");
            Console.ReadLine();
        }
    }

回答 (Answer)

As you might know, static constructor is called automatically before the first instance is created or any static members are referenced. And only then public constructor is called. But in this case, we are in console application and public constructor doesn’t called.

您可能知道,在创建第一个实例或引用任何静态成员之前,将自动调用静态构造函数。 然后只有公共构造函数被调用。 但是在这种情况下,我们在控制台应用程序中,并且没有调用public构造函数。

10. What would be displayed as result?

10.结果将显示什么?

[Flags]
      public enum Status 
      {
         Funny = 0x01,
         Hilarious = 0x02,
         Boring = 0x04,
         Cool = 0x08,
         Interesting = 0x10,
         Informative = 0x20,
         Error = 0x40
      }

  public static void Main (string[] args) {
         var code = 24;
         Console.WriteLine (String.Format("This Quiz is: {0}",  (Status)code));
      }

回答 (Answer)

24 that would be 0011000 in binary system

24在二进制系统中为0011000

Writing numbers in column

在栏中写数字

Funny = 0

有趣= 0

Hilarious = 0

搞笑= 0

Boring = 0

无聊= 0

Cool = 1

酷= 1

Interesting = 1

有趣= 1

Informative = 0

信息量= 0

Error = 0

错误= 0

Credits:

学分:

C# Often Surprises Me, part: 000001 C#常让我惊讶,部分:000001 Enumeration types (C# reference) 枚举类型(C#参考)

11. Where is a difference between String and string?

11.字符串和字符串之间有何区别?

回答 (Answer)

Use next link to get more details Difference between string and String in C#

使用下一个链接获取更多详细信息C#中的字符串和字符串之间的区别

12. What does mean (or at least has meant initially) Visual Studio sign?

12. Visual Studio标志是什么意思(至少起初是什么意思)?

13. Please match:

13.请匹配:

Async/await

异步/等待

Try/catch

试着抓

ValidateAntiForgeryToken

ValidateAntiForgeryToken

with abbreviations:

缩写:

TAP (TAP)

,

SEH (SEH)

,

STP (STP)

回答 (Answer)

Try/catch -> SEH (Structured Exception Handling)

尝试/捕获-> SEH(结构化异常处理)

ValidateAntiForgeryToken -> STP (Synchronizer Token Pattern)

ValidateAntiForgeryToken-> STP(同步器令牌模式)

14. Which one is not .NET CMS?

14.哪个不是.NET CMS?

a) mojoPortal

a)mojoPortal

b) N2 CMS

b)N2 CMS

c) Atomic CMS

c)原子CMS

d) Composite C1

d)复合C1

e) Concrete5

e)混凝土5

f) Piranha CMS

f)食人鱼CMS

回答 (Answer)

15. What would be displayed on the screen?

15.屏幕上将显示什么?

class Program
    {
        private static int y = x;
        private static int x = 5;

        static void Main(string[] args)
        {
            Console.WriteLine(y);
            Console.ReadLine();
        }
    }

回答 (Answer)

Sometimes declaring variables order plays a role.

有时,声明变量顺序很重要。

16. Which Concurrent Collection class is missing in .Net

16. .Net中缺少哪个并发集合类

a) ConcurrentQueue

a)ConcurrentQueue

b) ConcurrentStack

b)并发堆栈

c) ConcurrentList

c)并发列表

d) ConcurrentDictionary

d)并发词典

e) ConcurrentBag

e)并发袋

回答 (Answer)

17. What is the preferable way to run async code synchronously (if it’s not possible to use await):

17.同步运行异步代码的最佳方法是什么(如果不可能使用等待):

a) Wait()

a)等待()

b) Result()

b)结果()

c) GetAwaiter().GetResult()

c)GetAwaiter()。GetResult()

回答 (Answer)

Wait and Result are throwing aggregate exception instead of normal

等待和结果抛出聚合异常,而不是正常

Credits: Correcting Common Async/Await Mistakes in .NET — Brandon Minnick

鸣谢: 纠正.NET中常见的异步/等待错误-Brandon Minnick

翻译自: https://habr.com/en/post/498470/

c#之.net 版本问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值