我试了,可是报错:无法将类型“object”隐式转换为string。
我不知道显式转换该如何写,请高手指教。
谢谢楼上,中秋快乐。
我不知道显式转换该如何写,请高手指教。
谢谢楼上,中秋快乐。
解决方案 »
- 提问:如何在Winform中添加网络视频
- 求助关于json字符串解析的问题
- winform用dataset绑定datagridview冻结某列问题
- 向高手们请教一个比较难的问题,把控件内容以图片形式保存出来
- 本人的毕业设计 中 碰到的一个问题,还望高手指点
- [求助]一个简单的问题,C#的网站问题.
- 请问如何取得XML中的CDADA区域内的函数
- 关于IDL文件内容转换为c#接口的问题。
- ASP.NET MVC3部署到IIS上出现错误
- 关于绑定时的null的问题。
- [在线等]remoting中一个奇怪的问题,到底能否一个EXE文件还是一个DLL文件。分不够我再开贴
- 请教如何将水晶报表两个查询结果的记录先后显示,而不是间隔显示?
示例
下列示例说明如何创建和初始化 Hashtable,以及如何打印出其键和值。
[Visual Basic]
Imports System
Imports System.Collections
Imports Microsoft.VisualBasicPublic Class SamplesHashtable
Public Shared Sub Main()
' Creates and initializes a new Hashtable.
Dim myHT As New Hashtable()
myHT.Add("First", "Hello")
myHT.Add("Second", "World")
myHT.Add("Third", "!")
' Displays the properties and values of the Hashtable.
Console.WriteLine("myHT")
Console.WriteLine(" Count: {0}", myHT.Count)
Console.WriteLine(" Keys and Values:")
PrintKeysAndValues(myHT)
End Sub
Public Shared Sub PrintKeysAndValues(myList As Hashtable)
Dim myEnumerator As IDictionaryEnumerator = myList.GetEnumerator()
Console.WriteLine(ControlChars.Tab + "-KEY-" + ControlChars.Tab _
+ "-VALUE-")
While myEnumerator.MoveNext()
Console.WriteLine(ControlChars.Tab + "{0}:" + ControlChars.Tab _
+ "{1}", myEnumerator.Key, myEnumerator.Value)
End While
Console.WriteLine()
End Sub
End Class' This code produces the following output.
'
' myHT
' Count: 3
' Keys and Values:
' -KEY- -VALUE-
' Third: !
' Second: World
' First: Hello
[C#]
using System;
using System.Collections;
public class SamplesHashtable { public static void Main() { // Creates and initializes a new Hashtable.
Hashtable myHT = new Hashtable();
myHT.Add("First", "Hello");
myHT.Add("Second", "World");
myHT.Add("Third", "!"); // Displays the properties and values of the Hashtable.
Console.WriteLine( "myHT" );
Console.WriteLine( " Count: {0}", myHT.Count );
Console.WriteLine( " Keys and Values:" );
PrintKeysAndValues( myHT );
}
public static void PrintKeysAndValues( Hashtable myList ) {
IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
Console.WriteLine( "\t-KEY-\t-VALUE-" );
while ( myEnumerator.MoveNext() )
Console.WriteLine("\t{0}:\t{1}", myEnumerator.Key, myEnumerator.Value);
Console.WriteLine();
}
}
/*
This code produces the following output.myHT
Count: 3
Keys and Values:
-KEY- -VALUE-
Third: !
Second: World
First: Hello
*/