本文整理汇总了C#中NameValueCollection.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.ToString方法的具体用法?C# NameValueCollection.ToString怎么用?C# NameValueCollection.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameValueCollectionAdd
public void NameValueCollectionAdd()
{
NameValueCollection nvc = new NameValueCollection();
nvc.Add("anint", 17);
nvc.Add("adouble", 1.234);
nvc.Add("astring", "bugs bunny");
nvc.Add("aguid", Guid.Empty);
nvc.Count.Should().Be(4);
nvc.GetValue<int>("anint").Should().Be(17);
nvc.GetValue<double>("adouble").Should().Be(1.234);
nvc.GetValue<string>("astring").Should().Be("bugs bunny");
nvc.GetValue<Guid>("aguid").Should().Be(Guid.Empty);
int i = 1;
10.Times(() => nvc.Add("x" + i, i++));
nvc.ToString().Should().Contain("anint");
nvc.ToString().Should().Contain("17");
nvc.ToString().Should().Contain("adouble");
nvc.ToString().Should().Contain("bugs bunny");
nvc.ToString().Should().Contain("aguid");
nvc.ToString().Should().Contain("...");
}
示例2: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
NameValueCollection nvc;
try
{
Console.WriteLine("--- default ctor ---");
strLoc = "Loc_001oo";
iCountTestcases++;
nvc = new NameValueCollection();
Console.WriteLine("1. compare to null");
iCountTestcases++;
if (nvc == null)
{
iCountErrors++;
Console.WriteLine("Err_0001, collection is null after default ctor");
}
Console.WriteLine("2. check Count");
iCountTestcases++;
if (nvc.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002, Count = {0} after default ctor", nvc.Count);
}
Console.WriteLine("3. check Get(some_key)");
iCountTestcases++;
if (nvc.Get("key") != null)
{
iCountErrors++;
Console.WriteLine("Err_0003, Get(some_key) returned non-null after default ctor");
}
Console.WriteLine("4. check ToString()");
iCountTestcases++;
string temp = nvc.ToString();
Console.WriteLine(" ToString(): " + temp);
if (temp.IndexOf("NameValueCollection") == -1)
{
iCountErrors++;
Console.WriteLine("Err_0004, ToString() doesn't contain \"NameValueCollection\"");
}
Console.WriteLine("5. check returned Type");
iCountTestcases++;
temp = nvc.GetType().ToString().Trim();
Console.WriteLine(" GetType(): " + temp);
if (temp.IndexOf("NameValueCollection") == -1)
{
iCountErrors++;
Console.WriteLine("Err_0005: returned type doesn't contain \"NameValueCollection\"");
}
Console.WriteLine("6. compare returned Type of two collection");
iCountTestcases++;
string temp1 = (new NameValueCollection()).GetType().ToString().Trim();
if (String.Compare(temp, temp1) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0006: returned types of two collections differ");
}
Console.WriteLine("7. check AllKeys array");
iCountTestcases++;
string [] keys = nvc.AllKeys;
if ( keys.Length != 0)
{
iCountErrors++;
Console.WriteLine("Err_0007: AllKeys contains {0} keys after default ctor", keys.Length);
}
Console.WriteLine("8. check Item(some_key)");
iCountTestcases++;
if (nvc["key"] != null)
{
iCountErrors++;
Console.WriteLine("Err_0008: Item(some_key) returned non-null after default ctor");
}
Console.WriteLine("9. Add(name, value)");
iCountTestcases++;
nvc.Add("Name", "Value");
if (nvc.Count != 1)
{
iCountErrors++;
Console.WriteLine("Err_0009a: Count returned {0} instead of 1", nvc.Count);
}
if (String.Compare(nvc["Name"], "Value", false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0009b: Item() returned unexpected value");
}
Console.WriteLine("10. Clear()");
iCountTestcases++;
nvc.Clear();
if (nvc.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_00010a: Count returned {0} instead of 0 after Clear()", nvc.Count);
}
if (nvc["Name"] != null)
{
iCountErrors++;
Console.WriteLine("Err_00010b: Item() returned non-null value after Clear()");
//.........这里部分代码省略.........
示例3: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
NameValueCollection nvc;
NameValueCollection nvc1;
string [] values =
{
"",
" ",
"a",
"aa",
"tExt",
" SPaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] names =
{
"zero",
"oNe",
" ",
"",
"aA",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
try
{
Console.WriteLine("--- default ctor ---");
strLoc = "Loc_001oo";
iCountTestcases++;
nvc1 = new NameValueCollection();
Console.WriteLine("1. Create from another empty collection");
nvc = new NameValueCollection(nvc1);
Console.WriteLine("1.1 compare to null");
iCountTestcases++;
if (nvc == null)
{
iCountErrors++;
Console.WriteLine("Err_0001.1, collection is null");
}
Console.WriteLine("1.2. check Count");
iCountTestcases++;
if (nvc.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001.2, Count = {0} ", nvc.Count);
}
Console.WriteLine("1.3. check Get(some_key)");
iCountTestcases++;
if (nvc.Get("key") != null)
{
iCountErrors++;
Console.WriteLine("Err_0001.3, Get(some_key) returned non-null after default ctor");
}
Console.WriteLine("1.4. check ToString()");
iCountTestcases++;
string temp = nvc.ToString();
Console.WriteLine(" ToString(): " + temp);
if (temp.IndexOf("NameValueCollection") == -1)
{
iCountErrors++;
Console.WriteLine("Err_0001.4, ToString() doesn't contain \"NameValueCollection\"");
}
Console.WriteLine("1.5. check returned Type");
iCountTestcases++;
temp = nvc.GetType().ToString().Trim();
Console.WriteLine(" GetType(): " + temp);
if (temp.IndexOf("NameValueCollection") == -1)
{
iCountErrors++;
Console.WriteLine("Err_0001.5: returned type doesn't contain \"NameValueCollection\"");
}
Console.WriteLine("1.6. compare returned Type of two collection");
iCountTestcases++;
string temp1 = (new NameValueCollection()).GetType().ToString().Trim();
if (String.Compare(temp, temp1) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001.6: returned types of two collections differ");
}
Console.WriteLine("1.7. check AllKeys array");
iCountTestcases++;
string [] keys = nvc.AllKeys;
if ( keys.Length != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001.7: AllKeys contains {0} keys after default ctor", keys.Length);
}
Console.WriteLine("1.8. check Item(some_key)");
//.........这里部分代码省略.........