可以简化对象初始化。 [英] Object Initialization can be simplified.

查看:284
本文介绍了可以简化对象初始化。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个C#代码。

public void ThrowApplException ( string caption, string className )
        {
            ApplicationException ex = new ApplicationException ( "DataReader: no rows in " + caption + " in " + className );
            ExceptionMessageBox emb = new ExceptionMessageBox ( ex );  // <== message
            emb.Caption = caption;
            Form1 form1 = new Form1 ( );
            emb.Show ( form1 );
            throw ex;
        }                                               // ThrowApplException

然后我进行调试,并出现标题中的消息。

Then I do debug and a message comes up which is in the title.

怎么能我简化了吗?

谢谢, - MyCatAlex

Thanks, - MyCatAlex

推荐答案

出现消息时,单击Visual Studio显示的小符号嵌套到源代码中的消息。 Visual Studio将向您展示它建议简化代码的方式。

When the message appears, click the little symbol that Visual Studio displays nest to the message in the source code. Visual Studio will show to you which is the way in which it proposes to simplify the code.

请注意,Visual Studio提出的大多数这些简化都使用新的C#7功能,因此您的代码将与旧版本的编译器不兼容。

Be warned that most of these simplifications proposed by Visual Studio use new C# 7 features, so your code will become incompatible with older versions of the compiler.


这篇关于可以简化对象初始化。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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