考虑我有一个Dictionary<Key,List<item>>
TestDictionary
如果我做 :
List<item> someCollection;
TestDictionary.TryGetValue(someKey,out someCollection); //assuming that someCollection will not return null;
someCollection.add(someItem);
Run Code Online (Sandbox Code Playgroud)
将对象someItem添加到Dictionary值TestDictionary [someKey]中的集合中吗?
代码 :
<telerik:RadListView ID="RadListView1" Width="100%" AllowPaging="True" runat="server"
Skin="Metro" allowsorting="true" ItemPlaceholderID="ProductsHolder" DataKeyNames="Product_ID" GroupPlaceholderID="CategoryHolder"
GroupItemCount="4" >
<GroupTemplate>
<fieldset style="float: left; width: 330px; margin-right: 15px;">
<legend><%#Eval("CATEGORY_NAME") %></legend>
<table>
<tr>
<td>
<asp:Panel ID="CategoryHolder" runat="server"></asp:Panel>
</td>
</tr>
</table>
</fieldset>
</GroupTemplate>
<LayoutTemplate>
<fieldset style="width: 100%; margin: 0 auto; border: none;" id="FieldSet1">
<telerik:RadDataPager ID="RadDataPager2" runat="server" PagedControlID="RadListView1"
Visible='<%# Container.PageCount != 1%>' Skin="Metro" PageSize="52">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" FirstButtonText="First" PrevButtonText="Prev"
HorizontalPosition="LeftFloat" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" NextButtonText="Next" LastButtonText="Last"
HorizontalPosition="RightFloat" />
</Fields>
</telerik:RadDataPager>
<br />
<asp:Panel ID="ProductsHolder" runat="server">
</asp:Panel>
<table …
Run Code Online (Sandbox Code Playgroud) package main
import "fmt"
func main() {
blaa := map[string]string{
"key": "value",
getKey(): "value2", //replacing getKey() with "key" results in compile time error.
}
fmt.Println("Hello, " + blaa["key"])
}
func getKey() string {
return "key"
}
Run Code Online (Sandbox Code Playgroud)
运行上面的程序将打印“Hello, value2”。在这里尝试一下https://go.dev/play/p/s92LaaNc3n4
虽然我可以看到密钥被覆盖,但我想知道为什么这panic
在运行时不会被覆盖?使用两个字符串文字"key"
将导致编译时错误,这是预期的行为。