当前位置: 首页>>代码示例>>C#>>正文


C# NameValueCollection.Clear方法代码示例

本文整理汇总了C#中NameValueCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.Clear方法的具体用法?C# NameValueCollection.Clear怎么用?C# NameValueCollection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NameValueCollection的用法示例。


在下文中一共展示了NameValueCollection.Clear方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: runTest


//.........这里部分代码省略.........
         }
         if (nvc.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( String.Compare(nvc.GetKey(i), keys[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, returned: \"{1}\", expected \"{2}\"", i, nvc.GetKey(i), keys[i]);
             }  
         }
         Console.WriteLine("3. add intl strings GetKey()");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         string [] intlValues = new string [len * 2];
         for (int i = 0; i < len*2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         Boolean caseInsensitive = false;
         for (int i = 0; i < len * 2; i++) 
         {
             if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                 caseInsensitive = true;
         }
         iCountTestcases++;
         nvc.Clear();
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(intlValues[i+len], intlValues[i]);
         } 
         if ( nvc.Count != (len) ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, len);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( String.Compare(nvc.GetKey(i), intlValues[i+len], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, returned \"{1}\" instead of \"{2}\"", i, nvc.GetKey(i), intlValues[i+len]);
             }  
         }
         Console.WriteLine("4. case sensitivity");
         strLoc = "Loc_004oo"; 
         string [] intlValuesLower = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             intlValues[i] = intlValues[i].ToUpper();
         }
         for (int i = 0; i < len * 2; i++) 
         {
             intlValuesLower[i] = intlValues[i].ToLower();
         } 
         nvc.Clear();
         for (int i = 0; i < len; i++) 
         {
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co8727getkey_int.cs

示例2: runTest


//.........这里部分代码省略.........
         nvc = new NameValueCollection();
         cnt = nvc.Count;
         if ( cnt != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, count is {0} instead of {1} after default ctor", nvc.Count, 0);
         }
         Console.WriteLine("1. call HasKeys() on empty collection");
         strLoc = "Loc_001oa"; 
         iCountTestcases++;
         if ( nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, HasKeys returned true after default ctor");
         }
         Console.WriteLine("2. add simple strings and call HasKeys()");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = nvc.Count;
         for (int i = 0; i < values.Length; i++) 
         {    
             nvc.Add(keys[i], values[i]);
         }
         if (nvc.Count != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length);
         }
         iCountTestcases++;
         if ( !nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002b, returned false for collection with {0} items", nvc.Count);
         }
         Console.WriteLine("3. add intl strings and call HasKeys()");
         strLoc = "Loc_003oo"; 
         int len = values.Length;
         string [] intlValues = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         cnt = nvc.Count;
         iCountTestcases++;
         for (int i = 0; i < len; i++) 
         {    
             nvc.Add(intlValues[i+len], intlValues[i]);
         }
         if (nvc.Count != (cnt + len)) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, cnt + len);
         }
         iCountTestcases++;
         if ( !nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, returned false for collection with {0} items", nvc.Count);
         }
         Console.WriteLine("4. add item with null-key and call HasKeys()");
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         nvc.Clear();
         cnt = nvc.Count;
         for (int i = 0; i < values.Length; i++) 
         {    
             nvc.Add(null, values[i]);
         }
         if (nvc.Count != 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, count is {0} instead of {1}", nvc.Count, 1);
         }
         iCountTestcases++;
         Console.WriteLine(" HasKeys() returns: " + nvc.HasKeys());
         if ( nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004b, returned true for collection null-key");
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8730haskeys.cs

示例3: readSectionValues

	//读取指定的Section的所有Value到列表中
	public void readSectionValues(string Section, NameValueCollection Values)
	{
		StringCollection KeyList = new StringCollection();
		readSection(Section, KeyList);
		Values.Clear();
		foreach (string key in KeyList)
		{
			Values.Add(key, readString(Section, key, ""));
		}
	}
开发者ID:gfxmode,项目名称:LIB,代码行数:11,代码来源:IniHandler.cs

示例4: runTest


//.........这里部分代码省略.........
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             cnt = nvc.Count;
             nvc.Add(intlValues[i+len], intlValues[i]);
             if (nvc.Count != cnt+1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}a, count is {1} instead of {2}", i, nvc.Count, cnt+1);
             } 
             iCountTestcases++;
             if (Array.IndexOf(nvc.AllKeys, intlValues[i+len]) < 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, collection doesn't contain key of new item", i);
             } 
             iCountTestcases++;
             if (String.Compare(nvc[intlValues[i+len]], intlValues[i], false) != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, returned item \"{1}\" instead of \"{2}\"", i, nvc[intlValues[i+len]], intlValues[i]);
             } 
         }
         Console.WriteLine("3. Case sensitivity");
         string [] intlValuesLower = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             intlValues[i] = intlValues[i].ToUpper();
         }
         for (int i = 0; i < len * 2; i++) 
         {
             intlValuesLower[i] = intlValues[i].ToLower();
         } 
         nvc.Clear();
         Console.WriteLine(" initial number of items: " + nvc.Count);
         strLoc = "Loc_003oo"; 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             cnt = nvc.Count;
             nvc.Add(intlValues[i+len], intlValues[i]);
             if (nvc.Count != cnt+1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}a, count is {1} instead of {2}", i, nvc.Count, cnt+1);
             } 
             iCountTestcases++;
             if (Array.IndexOf(nvc.AllKeys, intlValues[i+len]) < 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, collection doesn't contain key of new item", i);
             } 
             iCountTestcases++;
             if (String.Compare(nvc[intlValues[i+len]], intlValues[i], false) != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, returned item \"{1}\" instead of \"{2}\"", i, nvc[intlValues[i+len]], intlValues[i]);
             } 
             iCountTestcases++;
             if (!caseInsensitive && String.Compare(nvc[intlValuesLower[i+len]], intlValuesLower[i], false) == 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}d, returned item \"{1}\" is lowercase after adding uppercase", i, nvc[intlValuesLower[i+len]]);
             } 
             iCountTestcases++;
             if (!caseInsensitive && Array.IndexOf(nvc.AllKeys, intlValuesLower[i+len]) >= 0) 
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co8722add_str_str.cs

示例5: runTest


//.........这里部分代码省略.........
         {
             iCountTestcases++;
             vls = nvc.GetValues(keys[i]);
             if (vls.Length != 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, returned number of strings {1} instead of 1", i, vls.Length);
             } 
             iCountTestcases++;
             if ( String.Compare(vls[0], values[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, returned: \"{1}\", expected \"{2}\"", i, vls[0], values[i]);
             }  
         }
         Console.WriteLine("3. add intl strings GetValues()");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         string [] intlValues = new string [len * 2];
         for (int i = 0; i < len*2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         Boolean caseInsensitive = false;
         for (int i = 0; i < len * 2; i++) 
         {
             if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                 caseInsensitive = true;
         }
         iCountTestcases++;
         nvc.Clear();
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(intlValues[i+len], intlValues[i]);
         } 
         if ( nvc.Count != (len) ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, len);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             vls = nvc.GetValues(intlValues[i+len]);
             if (vls.Length != 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, returned number of strings {1} instead of 1", i, vls.Length);
             } 
             iCountTestcases++;
             if ( String.Compare(vls[0], intlValues[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}c, returned \"{1}\" instead of \"{2}\"", i, vls[0], intlValues[i]);
             }  
         }
         Console.WriteLine("4. case sensitivity");
         strLoc = "Loc_004oo"; 
         string [] intlValuesLower = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             intlValues[i] = intlValues[i].ToUpper();
         }
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co8729getvalues_str.cs

示例6: 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()");
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8718ctor.cs

示例7: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     NameValueCollection nvc; 
     NameValueCollection nvc1; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aA",
         "text",
         "     SPaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "oNe",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         nvc = new NameValueCollection();
         nvc1 = new NameValueCollection();
         Console.WriteLine("1. Add(empty_coll) to empty collection");
         iCountTestcases++;
         nvc.Clear();
         nvc1.Clear();
         nvc.Add(nvc1);
         iCountTestcases++;
         if ( nvc.Count != 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, count is {0} instead of 0", nvc.Count);
         }     		
         Console.WriteLine("2. Add(simple_strings_coll) to empty collection");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         nvc.Clear();
         cnt = nvc.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(keys[i], values[i]);
         }
         if (nvc.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length);
         } 
         iCountTestcases++;
         nvc1.Clear();
         nvc1.Add(nvc);
         if (nvc1.Count != nvc.Count) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002b, count is {0} instead of {1}", nvc1.Count, nvc.Count);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( String.Compare(nvc1[keys[i]], values[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, returned: \"{1}\", expected \"{2}\"", i, nvc[keys[i]], values[i]);
             }  
         }
         Console.WriteLine("3. Add(simple_strings_coll) to simple_string_collection");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         len = values.Length;
         if (nvc.Count < len) 
         {
             nvc.Clear();
             for (int i = 0; i < len; i++) 
             {
                 nvc.Add(keys[i], values[i]);
             }
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8776add_nvc.cs

示例8: runTest


//.........这里部分代码省略.........
                 if (String.Compare(destination[i], values[i], false) != 0) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty collection", i);
                 }
             } 
         }
         Console.WriteLine("3. add simple strings and CopyTo(Array, 0)");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         cnt = nvc.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(keys[i], values[i]);
         }
         if (nvc.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, values.Length);
         } 
         destination = new string [len];
         nvc.CopyTo(destination, 0);
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( String.Compare(nvc[i], destination[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i], nvc[i]);
             }  
         }
         Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length);
         nvc.Clear();
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(keys[i], values[i]);
         }
         if (nvc.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, count is {0} instead of {1}", nvc.Count, values.Length);
         } 
         destination = new string[len*2];
         nvc.CopyTo(destination, len);
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( String.Compare(nvc[i], destination[i+len], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i+len], nvc[i]);
             }  
         }
         Console.WriteLine("5. add intl strings and CopyTo(Array, 0)");
         strLoc = "Loc_005oo"; 
         iCountTestcases++;
         string [] intlValues = new string [len * 2];
         for (int i = 0; i < len*2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co8724copyto_array_int.cs

示例9: runTest


//.........这里部分代码省略.........
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, cnt+len);
         } 
         for (int i = 0; i < len; i++) 
         {
             cnt = nvc.Count;
             iCountTestcases++;
             nvc.Remove(intlValues[i+len]);
             if (nvc.Count != cnt - 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, returned: failed to remove item", i);
             } 
             ks = nvc.AllKeys;
             iCountTestcases++;
             if ( Array.IndexOf(ks, intlValues[i+len]) > -1 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}c, removed wrong item", i);
             }  
         }
         Console.WriteLine("4. case sensitivity");
         strLoc = "Loc_004oo"; 
         string [] intlValuesLower = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             intlValues[i] = intlValues[i].ToUpper();
         }
         for (int i = 0; i < len * 2; i++) 
         {
             intlValuesLower[i] = intlValues[i].ToLower();
         } 
         nvc.Clear();
         Console.WriteLine("   - add uppercase and remove uppercase");
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(intlValues[i+len], intlValues[i]);     
         }
         for (int i = 0; i < len; i++) 
         {
             cnt = nvc.Count;
             iCountTestcases++;
             nvc.Remove(intlValues[i+len]);
             if (nvc.Count != cnt - 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0004_{0}b, returned: failed to remove item", i);
             } 
             ks = nvc.AllKeys;
             iCountTestcases++;
             if ( Array.IndexOf(ks, intlValues[i+len]) > -1 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0004_{0}c, removed wrong item", i);
             } 
         } 
         nvc.Clear();
         Console.WriteLine("   - add uppercase but remove lowercase");
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(intlValues[i+len], intlValues[i]);     
         }
         for (int i = 0; i < len; i++) 
         {
             cnt = nvc.Count;
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co8731remove_str.cs

示例10: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     NameValueCollection nvc; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aA",
         "text",
         "     SPaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "oNe",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     int cnt = 0;            
     string itm;         
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         nvc = new NameValueCollection();
         Console.WriteLine("1. set Item(string) on empty collection");
         iCountTestcases++;
         nvc.Clear();
         Console.WriteLine("     - Item(null)");
         nvc[null] = "nullItem";
         iCountTestcases++;
         if ( nvc.Count != 1 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, failed to add item");
         }     		
         iCountTestcases++;
         if ( nvc[null] == null ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, returned null");
         }
         else 
         {
             iCountTestcases++;
             if ( String.Compare(nvc[null], "nullItem", false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001c, wrong value");
             }
         }
         nvc.Clear();
         Console.WriteLine("     - Item(some_string)");
         nvc["some_string"] = "someItem";
         iCountTestcases++;
         if ( nvc.Count != 1 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001d, failed to add item");
         }     		
         iCountTestcases++;
         if ( nvc["some_string"] == null ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001e, returned null");
         }
         else 
         {
             iCountTestcases++;
             if ( String.Compare(nvc["some_string"], "someItem", false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001f, wrong value");
             }
         }
         Console.WriteLine("2. add simple strings, set them via Item(string)");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         nvc.Clear();
         cnt = nvc.Count;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8736set_item_str_str.cs

示例11: runTest


//.........这里部分代码省略.........
         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)");
         iCountTestcases++;
         if (nvc["key"] != null) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0001.8: Item(some_key) returned non-null after default ctor");
         }
         Console.WriteLine("1.9. Add(name, value)");
         iCountTestcases++;
         nvc.Add("Name", "Value");
         if (nvc.Count != 1) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0001.9a: Count returned {0} instead of 1", nvc.Count);
         }
         if (String.Compare(nvc["Name"], "Value", false) != 0)  
         {  
             iCountErrors++;
             Console.WriteLine("Err_0001.9b: Item() returned unexpected value");
         }
         Console.WriteLine("1.10. Clear()");
         iCountTestcases++;
         nvc.Clear();
         if (nvc.Count != 0) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0001.10a: Count returned {0} instead of 0 after Clear()", nvc.Count);
         }
         if (nvc["Name"] != null)  
         {  
             iCountErrors++;
             Console.WriteLine("Err_0001.10b: Item() returned non-null value after Clear()");
         }
         Console.WriteLine("2. Create from filled collection");
         int len = values.Length;
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         for (int i = 0 ; i < len; i ++) 
         {
             nvc1.Add(names[i], values[i]);
         }
         if (nvc1.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, Count = {0} after instead of {1}", nvc.Count, len);
         }
         nvc = new NameValueCollection(nvc1);
         Console.WriteLine("2.1. check Count");
         iCountTestcases++;
         if (nvc.Count != nvc1.Count) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002.1, Count = {0} instead of {1}", nvc.Count, nvc1.Count);
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co8719ctor_nvc.cs

示例12: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     NameValueCollection nvc; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aA",
         "text",
         "     SPaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "oNe",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     int cnt = 0;            
     string [] ks;          
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         nvc = new NameValueCollection();
         Console.WriteLine("1. AllKeys on empty collection");
         if (nvc.Count > 0 )
             nvc.Clear();
         ks = nvc.AllKeys;
         if (ks.Length != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001, number of keys is {0} instead of 0", ks.Length);
         } 
         Console.WriteLine("2. AllKeys on collection with simple strings");
         strLoc = "Loc_002oo"; 
         for (int i = 0; i < values.Length; i++) 
         {
             iCountTestcases++;
             cnt = nvc.Count;
             nvc.Add(keys[i], values[i]);
             if (nvc.Count != cnt+1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}a, count is {1} instead of {2}", i, nvc.Count, cnt+1);
             } 
             iCountTestcases++;
             if (nvc.AllKeys.Length != cnt+1 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, incorrects Keys array", i);
             } 
             iCountTestcases++;
             if (Array.IndexOf(nvc.AllKeys, keys[i]) < 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, collection doesn't contain key of new item", i);
             } 
         }
         Console.WriteLine("3. AllKeys on collection with intl strings");
         int len = values.Length;
         string [] intlValues = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         Boolean caseInsensitive = false;
         for (int i = 0; i < len * 2; i++) 
         {
             if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                 caseInsensitive = true;
         }
         Console.WriteLine(" initial number of items: " + nvc.Count);
         strLoc = "Loc_003oo"; 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8733get_allkeys.cs

示例13: CreateWebRequest

            /// <summary>
            /// This method creates secure/non secure web
            /// request based on the parameters passed.
            /// </summary>
            /// <param name="uri"></param>
            /// <param name="collHeader">This parameter of type
            ///    NameValueCollection may contain any extra header
            ///    elements to be included in this request      </param>
            /// <param name="RequestMethod">Value can POST OR GET</param>
            /// <param name="NwCred">In case of secure request this would be true</param>
            /// <returns></returns>
            public virtual HttpWebRequest CreateWebRequest(string uri,
              NameValueCollection collHeader,
              string RequestMethod, bool NwCred)
            {
                HttpWebRequest webrequest =
                 (HttpWebRequest)WebRequest.Create(uri);
                webrequest.KeepAlive = false;
                webrequest.Method = RequestMethod;

                int iCount = collHeader.Count;
                string key;
                string keyvalue;

                for (int i = 0; i < iCount; i++)
                {
                    key = collHeader.Keys[i];
                    keyvalue = collHeader[i];
                    webrequest.Headers.Add(key, keyvalue);
                }

                webrequest.ContentType = "text/html";
                //"application/x-www-form-urlencoded";

                if (ProxyServer.Length > 0)
                {
                    webrequest.Proxy = new
                     WebProxy(ProxyServer, ProxyPort);
                }
                webrequest.AllowAutoRedirect = false;

                if (NwCred)
                {
                    CredentialCache wrCache =
                            new CredentialCache();
                    wrCache.Add(new Uri(uri), "Basic",
                      new NetworkCredential(UserName, UserPwd));
                    webrequest.Credentials = wrCache;
                }
                //Remove collection elements
                collHeader.Clear();
                return webrequest;
            }//End of secure CreateWebRequest
开发者ID:pold500,项目名称:vk_downloader,代码行数:53,代码来源:BaseRequestStream.cs


注:本文中的NameValueCollection.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。