C# 语法快捷方式

发布于 2024-08-04 18:51:19 字数 95 浏览 6 评论 0原文

我想知道是否存在 C# 语法快捷方式的集合或列表。事情很简单,省略 if 语句上的大括号一直到 ?? 合并运算符之类的事情。

I was wondering if there exists somewhere a collection or list of C# syntax shortcuts. Things as simple omitting the curly braces on if statements all the way up to things like the ?? coalesce operator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

冷弦 2024-08-11 18:51:19
a = b ? c : d ;

是 的缩写

if (b) a = c; else a = d;

并且

int MyProp{get;set;}

是 的缩写

int myVar;
int MyProp{get {return myVar; } set{myVar=value;}}

另请参阅 Visual Studio 中的代码模板,它可以让您加快编码速度。

但请注意,短代码并不一定意味着好的代码。

a = b ? c : d ;

is short for

if (b) a = c; else a = d;

And

int MyProp{get;set;}

is short for

int myVar;
int MyProp{get {return myVar; } set{myVar=value;}}

Also see the code templates in visual studio which allows you to speed coding up.

But note that short code doesn't mean necessarily good code.

七度光 2024-08-11 18:51:19

我一直最喜欢的是

a = b ?? c;

翻译成

if (b != null) then a = b; else a = c;

My all time favorite is

a = b ?? c;

which translates to

if (b != null) then a = b; else a = c;
情未る 2024-08-11 18:51:19

c# 6.0 有一些有趣的。 ?.? (空条件运算符)是我的最爱。

var value = obj != null ? obj.property : null; 变成

var value = obj?.property

var

value = list != null ? list[0] : null;

变成

var value = list?[0]

c# 6.0 has some fun ones. ?. and ? (null conditional operator) is my favorite.

var value = obj != null ? obj.property : null; turns into

var value = obj?.property

and

var value = list != null ? list[0] : null;

turns into

var value = list?[0]
倾其所爱 2024-08-11 18:51:19

您觉得这个 C# 基本参考 pdf 文档怎么样?

这是另一个 pdf

How does this C# basic reference pdf document looks to you?

Here's another pdf.

浮华 2024-08-11 18:51:19

我不知道预编译列表,但 C# 参考 (尤其是 C# 关键字部分)如果您愿意阅读一些内容,则简明地包含您正在寻找的信息。

I don't know of a precompiled list, but the C# Reference (especially the C# Keywords section) concisely contains the information you're looking for if you're willing to read a bit.

感性 2024-08-11 18:51:19

它们不是语法快捷方式,但片段是很棒的编码快捷方式。例如,输入 prop (tab)(tab) 会删除属性所需的代码。

http://msdn.microsoft.com/en-us /library/ms165392(VS.80).aspx

They are not syntax shortcuts, but snippets are great coding shortcuts. Typing prop (tab)(tab), for example, stubs out the code you need for a property.

http://msdn.microsoft.com/en-us/library/ms165392(VS.80).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文