[英]Multiassignment in VB like in C-Style languages
Is there a way to perform this in VB.NET like in the C-Style languages: 有没有办法在VB.NET中执行此操作,如在C风格的语言中:
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 扩展Mark的正确答案
This type of assignment style is not possible in VB.Net. 这种类型的赋值样式在VB.Net中是不可能的。 The C# version of the code works because in C# assignment is an expression which produces a value.
代码的C#版本有效,因为在C#赋值中是一个产生值的表达式。 This is why it can be chained in this manner.
这就是它可以以这种方式链接的原因。
In VB.Net assignment is a statement and not an expression. 在VB.Net中,赋值是一个语句而不是表达式。 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.
实际上,如果将代码“a = b”编写为表达式,则将其视为值比较而不是赋值。
Eric's recent blog post on this subject for C# Eric最近关于C#这个主题的博客文章
At a language level assignment is a statement and not an expression. 在语言级别,赋值是语句而不是表达式。
As soon as I post this, someone will provide an example of how to do it. 我发布此消息后,会有人提供如何操作的示例。 But I don't think it is possible .
但我不认为这是可能的 。 VB.NET treats the single equals in the r-value as a comparison.
VB.NET将r值中的单个等于视为比较。 For example:
例如:
Dim i As Integer
Dim j As Integer
i = 5
j = i = 4
Debug.Print(j.ToString())
j = i = 5
Debug.Print(j.ToString())
The above code prints 0 (false) and -1 (true). 上面的代码打印0(假)和-1(真)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.