小编MDi*_*sel的帖子

输入Cast Operator Precedence

今天我遇到了一个场景,同时在我的应用程序中实现了搜索功能,让我感到困惑.看看这个片段:

public string GetFirstProductName(SortedList<string, object> itemsList) {
    for (int i = 0; i < itemsList.Values.Count; i++) {
        if (itemsList.Values[i] is Product)
           // Doesn't Compile:
           // return (Product)itemsList.Values[i].ProductName;

           // Does compile. Precedence for the "." higher than the cast?
           return ((Product)itemsList.Values[i]).ProductName;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

那么,演员的优先权是什么?是演员吗?as关键字怎么样- 是运营商,它的优先级是什么?

c#

3
推荐指数
1
解决办法
719
查看次数

标签 统计

c# ×1