开发者

Weird behavior of conditional operator?

string sortedcolumn =
( dataGridView1.SortedColumn != null
? dataGridView1.SortedColumn.Name
: "username"
);

In above statment when dataGridView1.SortedColumn==null I get exception of dataGridView1.SortedColumn is null instead of getting value as "username" to sor开发者_如何学Pythontedcolumn var.

Any idea?


Possible causes:

  • dataGridView1 is a field or variable containing the value null.

  • dataGridView1 is a property getter that returns null.

  • SortedColumn is a weird property getter that returns something non-null the first time but null afterwards. (Very unlikely because then merely looking at it in the debugger would change the result.)

  • dataGridView1, SortedColumn, or Name is a property getter that throws the exception you are seeing.

  • dataGridView1.SortedColumn is of a type that overloads operator!=, which throws the exception you are seeing.

  • dataGridView1.SortedColumn.Name is of a type that implements implicit operator string, which throws the exception you are seeing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜