VB中的多重分配,例如C风格的语言 [英] Multiassignment in VB like in C-Style languages
问题描述
是否可以像在C-Style语言中那样在VB.NET中执行此操作?
Is there a way to perform this in VB.NET like in the C-Style languages:
struct Thickness
{
double _Left;
double _Right;
double _Top;
double _Bottom;
public Thickness(double uniformLength)
{
this._Left = this._Right = this._Top = this._Bottom = uniformLength;
}
}
推荐答案
扩展在马克的正确答案上
Expanding on Mark's correct answer
这种类型的分配样式在VB.Net中是不可能的。代码的C#版本有效,因为在C#赋值中是一个产生值的表达式。这就是为什么可以这种方式链接它的原因。
This type of assignment style is not possible in VB.Net. The C# version of the code works because in C# assignment is an expression which produces a value. This is why it can be chained in this manner.
在VB.Net中,赋值是语句而不是表达式。它不产生任何值,并且不能更改。实际上,如果您将代码 a = b作为表达式编写,它将被视为值比较而不是赋值。
In VB.Net assignment is a statement and not an expression. It produces no value and cannot be changed. In fact if you write the code "a = b" as an expression it will be treated as a value comparison and not an assignment.
Eric最近关于C#的博客文章
Eric's recent blog post on this subject for C#
- http://blogs.msdn.com/ericlippert/archive/2010/02/11/chaining-simple-assignments-is-not-so-simple.aspx
在语言级别,分配是语句而不是表达式。
At a language level assignment is a statement and not an expression.
这篇关于VB中的多重分配,例如C风格的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!