a = b = c = d究竟是什么意思? [英] What exactly does a = b = c = d mean??

查看:84
本文介绍了a = b = c = d究竟是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释以下代码如何评估:


string a =" a";

string b =" b";

string c =" c";

string d =" d";


a = b = c = d;


信不信由你,msdn上发布了类似的代码。我不能想象为什么有人想要像这样编程。看起来好像很可怕。


最好的问候

Johann Blake

解决方案

" Johann Blake" <乔********* @ yahoo.com> schrieb im Newsbeitrag

新闻:11 ********************* @ z14g2000cwz.googlegro ups.com ...

有人可以解释以下代码如何评估:

字符串a =" a" ;;
字符串b =" b" ;;
字符串c =" c" ;;
字符串d =" d";

a = b = c = d;




这意味着:采取d的值并将其分配给a,b和c。

相当于:

a = d; B = d; c = d;

或更精确:

c = d; B = C; a = b;


类似于x ++ assignemnts不仅改变变量的值,而且

也返回一个值,(赋值),burt在大多数情况下,它没有被使用。


> string a =" a";

string b =" b";
string c =" c";
string d =" d";

a = b = c = d;

信不信由你,msdn上发布了类似的代码。我无法想象为什么有人想要像这样编程。它看起来很可怕。



我不认为它是*那个*坏,它只是将c设置为d,然后b设置为c然后a

到b,所以他们都结束了。


现在这里有一些VB垃圾别人做了我必须维持正确

now(这是一个文本框的文本更改事件,其中包含要打印的

标签的数量 - 我现在要做的一件事就是更改它

标签从一台打印机打印,有些打印几周后再打印

另一台打印机)....

Private Sub txtnol_Change()

On Error GoTo errhandler

Dim X,Z

Dim StrTmp,StrTMP2 As String

Z = 0

如果Abs(txtnol)<> 1然后

如果左(cbclsl,1)=" C"然后

StrTmp = UCase(右(左(cbclsl,11),2))

Z = 1

ElseIf Left(cbclsl,1 )=L然后

StrTmp = UCase(右(左(cbclsl,13),2))

Z = 1

结束如果

结束如果

如果Z = 1那么

对于X = 12到17

StrTMP2 = UCase(右(左)(cbclsl .List(X),9),2))

如果StrTmp = StrTMP2那么

cbclsl = cbclsl.List(X)

退出对于

结束如果

下一页

结束如果

如果Abs(txtnol)> 50然后txtnol = 50

退出Sub

errhandler:

MessageBox" ACCESS DENIED !!!!"

结束

结束子

更糟糕的是那些声称拥有MCSD的人....


> MessageBox" ACCESS DENIED !!!!"


顺便说一下,那个MessageBox函数原来是一个函数,

检查了一个TMP文件一个网络共享,看它是否包含某个

数字(看起来像一个电话号码)。如果它显示消息,

否则它不会。当然,没有任何评论可以解释为什么或

任何东西,我的猜测是那个家伙已经上过如何编写

不可维护代码的课程。 />

Can someone explain how the following code evaluates:

string a = "a";
string b = "b";
string c = "c";
string d = "d";

a = b = c = d;

Believe it or not, a similar piece of code was published on msdn. I
can''t imagine why anyone would ever want to program like this. It looks
horrendous.

Best Regards
Johann Blake

解决方案

"Johann Blake" <jo*********@yahoo.com> schrieb im Newsbeitrag
news:11*********************@z14g2000cwz.googlegro ups.com...

Can someone explain how the following code evaluates:

string a = "a";
string b = "b";
string c = "c";
string d = "d";

a = b = c = d;



It means: take the value of d and assign it to a, b and c.
equivalent to:
a=d; b=d; c=d;
or more precise:
c=d; b=c; a=b;

similar to x++ assignemnts not only change the value of a variable, but
also return a value, (the assigned value), burt in most cases it''s not used.


> string a = "a";

string b = "b";
string c = "c";
string d = "d";

a = b = c = d;

Believe it or not, a similar piece of code was published on msdn. I
can''t imagine why anyone would ever want to program like this. It looks
horrendous.


I don''t think it''s *that* bad, it just sets c to d, then b to c and then a
to b, so they all end up d.

Now here''s some VB junk someone else did that I''m having to maintain right
now (this is the text change event for a textbox containing the number of
labels to print - one thing I''m having to do right now is change it so some
labels print from one printer and some get printed several weeks later on
another printer)....
Private Sub txtnol_Change()
On Error GoTo errhandler
Dim X, Z
Dim StrTmp, StrTMP2 As String
Z = 0
If Abs(txtnol) <> 1 Then
If Left(cbclsl, 1) = "C" Then
StrTmp = UCase(Right(Left(cbclsl, 11), 2))
Z = 1
ElseIf Left(cbclsl, 1) = "L" Then
StrTmp = UCase(Right(Left(cbclsl, 13), 2))
Z = 1
End If
End If
If Z = 1 Then
For X = 12 To 17
StrTMP2 = UCase(Right(Left(cbclsl.List(X), 9), 2))
If StrTmp = StrTMP2 Then
cbclsl = cbclsl.List(X)
Exit For
End If
Next
End If
If Abs(txtnol) > 50 Then txtnol = 50
Exit Sub
errhandler:
MessageBox "ACCESS DENIED!!!!"
End
End Sub
What''s worse is the guy who wrote that claims to have an MCSD....


> MessageBox "ACCESS DENIED!!!!"

By the way, that MessageBox function turned out to be a function that
checked a TMP file on a network share to see if it contained a certain
number (looks like a phone number). If it does it displays the message,
otherwise it doesn''t. Course there''s no comments in to explain why or
anything, my guess is that the guy''s took lessons in how to write
unmaintainable code.


这篇关于a = b = c = d究竟是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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