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


C# NameValueCollection.CopyTo方法代码示例

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


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

示例1: CopyTo_MultipleValues_SameName

        public void CopyTo_MultipleValues_SameName()
        {
            NameValueCollection nameValueCollection = new NameValueCollection();
            string name = "name";
            nameValueCollection.Add(name, "value1");
            nameValueCollection.Add(name, "value2");
            nameValueCollection.Add(name, "value3");

            string[] dest = new string[1];
            nameValueCollection.CopyTo(dest, 0);
            Assert.Equal(nameValueCollection[0], dest[0]);
        }
开发者ID:Corillian,项目名称:corefx,代码行数:12,代码来源:NameValueCollection.CopyToTests.cs

示例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;
     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"
     };
     string [] destination;
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         nvc = new NameValueCollection();
         Console.WriteLine("1. Copy empty collection into empty array");
         iCountTestcases++;
         destination = new string[]{};
         Console.WriteLine("     - CopyTo(arr, -1)");
         try 
         {
             nvc.CopyTo(destination, -1);
             iCountErrors++;
             Console.WriteLine("Err_0001a, no exception");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001b, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         Console.WriteLine("     - CopyTo(arr, 0)");
         try 
         {
             nvc.CopyTo(destination, 0);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001c, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         Console.WriteLine("     - CopyTo(arr, 1)");
         try 
         {
             nvc.CopyTo(destination, 1);
             iCountErrors++;
             Console.WriteLine("Err_0001d, no exception");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001e, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. Copy empty collection into non-empty array");
         iCountTestcases++;
         destination = new string[values.Length];
         for (int i = 0; i < values.Length; i++) 
         {
             destination[i] = values[i];
         }
         nvc.CopyTo(destination, 0);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8724copyto_array_int.cs


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