我一直在查看字典的 .NET 实现,因为我想了解是什么使字典 ContainsKey 和查找快速:http : //referencesource.microsoft.com/#mscorlib/system/collections/generic/dictionary.cs,15debc34d286fdb3
containsKey 函数基本上会导致下面列出的 FindEntry:
buckets 是一个整数数组,entries 是一个 Entry 对象数组,它们是包含 HashCode、TKey 和 TValue 的结构。
所以我知道这个查找很快,因为它是一个简单的数组查找。
private int FindEntry(TKey key) {
if( key == null) {
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}
if (buckets != null) {
int hashCode = comparer.GetHashCode(key) & 0x7FFFFFFF;
for (int i = buckets[hashCode % buckets.Length]; i >= 0; i = entries[i].next) {
if (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key)) return i;
}
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)
但是我试图理解这两行:
int hashCode = comparer.GetHashCode(key) & 0x7FFFFFFF;
for …Run Code Online (Sandbox Code Playgroud) <ComboBox Style="{StaticResource Combobox}" ItemContainerStyle="{StaticResource {x:Type ComboBoxItem}}" DisplayMemberPath="Name" SelectedValuePath="Name" HorizontalAlignment="Left" VerticalAlignment="Top" Width="180" Height="25" Foreground="Black">
<ComboBox.ItemsSource>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Name"/>
<Binding Path="Identifier"/>
</MultiBinding>
</ComboBox.ItemsSource>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
我正在尝试绑定以显示应绑定的详细信息列表的ComboBoxItems名称和属性。我怎样才能做到这一点?IdentifierComboBox.ItemSource
基本上ItemSource应该绑定到一个对象列表(称为“详细信息”),并且每个对象都ComboBoxItem应该显示每个对象的Name+属性。Identifier
我想将文件夹的所有图像一张一张地插入到 Excel 中递增的单元格中。
例如,图片 1 应插入单元格 E1,然后图片 2 插入单元格 E2,依此类推。
我的代码只能从该目录中的硬编码单元格中插入一张图片:
Sub Insert()
Dim myPict As Picture
Dim PictureLoc As String
PictureLoc = "C:\MyFolder\Picture1.png"
With Range("E1")
Set myPict = ActiveSheet.Pictures.Insert(PictureLoc)
.RowHeight = myPict.Height
myPict.Top = .Top
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With
End Sub
Run Code Online (Sandbox Code Playgroud)