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


C# StringCollection.Remove方法代码示例

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


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

示例1: Remove_DuplicateTest

 public static void Remove_DuplicateTest(StringCollection collection, string[] data)
 {
     // Only the first element will be removed.
     string[] first = data.Distinct().ToArray();
     Assert.All(first, element =>
     {
         Assert.True(collection.Contains(element));
         Assert.True(((IList)collection).Contains(element));
         collection.Remove(element);
         Assert.True(collection.Contains(element));
         Assert.True(((IList)collection).Contains(element));
     });
     Assert.Equal(data.Length - first.Length, collection.Count);
     for (int i = first.Length; i < data.Length; i++)
     {
         string element = data[i];
         Assert.True(collection.Contains(element));
         Assert.True(((IList)collection).Contains(element));
         collection.Remove(element);
         bool stillPresent = i < data.Length - first.Length;
         Assert.Equal(stillPresent, collection.Contains(element));
         Assert.Equal(stillPresent, ((IList)collection).Contains(element));
     }
     Assert.Equal(0, collection.Count);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:25,代码来源:StringCollectionTests.cs

示例2: Remove_NotPresentTest

 public static void Remove_NotPresentTest(StringCollection collection, string[] data)
 {
     collection.Remove(ElementNotPresent);
     Assert.Equal(data.Length, collection.Count);
     ((IList)collection).Remove(ElementNotPresent);
     Assert.Equal(data.Length, collection.Count);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:StringCollectionTests.cs

示例3: RemoveTest

 public static void RemoveTest(StringCollection collection, string[] data)
 {
     Assert.All(data, element =>
     {
         Assert.True(collection.Contains(element));
         Assert.True(((IList)collection).Contains(element));
         collection.Remove(element);
         Assert.False(collection.Contains(element));
         Assert.False(((IList)collection).Contains(element));
     });
     Assert.Equal(0, collection.Count);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:12,代码来源:StringCollectionTests.cs

示例4: UpdateIds

  private bool UpdateIds(StringCollection ids, DataTable table, UpdateMode mode)
  {
    bool updated = false;

    if (mode == UpdateMode.New && ids.Count > 0)
    {
      ids.Clear();
      updated = true;
    }

    foreach (DataRow row in table.Rows)
    {
      if (!row.IsNull(0))
      {
        string value = row[0].ToString();

        if (mode == UpdateMode.Remove)
        {
          if (ids.IndexOf(value) >= 0)
          {
            ids.Remove(value);
            updated = true;
          }
        }
        else
        {
          if (mode == UpdateMode.Add)
          {
            if (ids.IndexOf(value) < 0)
            {
              ids.Add(value);
              updated = true;
            }
          }
          else
          {
            ids.Add(value);
            updated = true;
          }
        }
      }
    }

    return updated;
  }
开发者ID:ClaireBrill,项目名称:GPV,代码行数:45,代码来源:SelectionHandler.cs

示例5: 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";
     StringCollection sc; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aa",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. Remove() from empty collection");
         for (int i = 0; i < values.Length; i++) 
         {
             iCountTestcases++;
             sc.Remove(values[i]);
             if (sc.Count != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001_{0}, Remove changed Count for empty collection", i);
             }
         } 
         Console.WriteLine("2. add simple strings and test Remove()");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         sc.Clear();
         sc.AddRange(values);
         if (sc.Count != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
         } 
         for (int i = 0; i < values.Length; i++) 
         {
             iCountTestcases++;
             if (!sc.Contains(values[i])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, doesn't contain {0} item", i);
             }
             cnt = sc.Count; 
             iCountTestcases++;
             sc.Remove(values[i]);
             if (sc.Count != cnt - 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}c, didn't remove anything", i);
             } 
             if (sc.Contains(values[i])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}d, removed wrong item", i);
             } 
         }
         Console.WriteLine("3. add intl strings and test Remove()");
         strLoc = "Loc_003oo"; 
         string [] intlValues = new string [values.Length];
         for (int i = 0; i < values.Length; 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;
         } 
         int len = values.Length;
         Boolean caseInsensitive = false;
         for (int i = 0; i < len; i++) 
         {
             if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                 caseInsensitive = true;
         }
         iCountTestcases++;
         sc.Clear();
         sc.AddRange(intlValues);
         if ( sc.Count != intlValues.Length ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, intlValues.Length);
         } 
         for (int i = 0; i < intlValues.Length; i++) 
         {
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8746remove_str.cs

示例6: PrepareIds

  private void PrepareIds(out StringCollection targetIds, out StringCollection filteredIds, out StringCollection selectionIds)
  {
    targetIds = _appState.TargetIds.Clone();
    selectionIds = _appState.SelectionIds.Clone();

    // segregate the target IDs that pass through the query from
    // those that do not

    if (String.IsNullOrEmpty(_appState.Query))
    {
      filteredIds = new StringCollection();
    }
    else
    {
      Configuration config = AppContext.GetConfiguration();
      Configuration.QueryRow query = config.Query.FindByQueryID(_appState.Query);

      using (OleDbCommand command = query.GetDatabaseCommand())
      {
        command.Parameters[0].Value = _appState.TargetIds.Join(",");

        if (command.Parameters.Count > 1)
        {
          command.Parameters[1].Value = AppUser.GetRole();
        }

        using (OleDbDataReader reader = command.ExecuteReader())
        {
          int mapIdColumn = reader.GetOrdinal("MapID");

          filteredIds = targetIds;
          targetIds = new StringCollection();

          while (reader.Read())
          {
            if (!reader.IsDBNull(mapIdColumn))
            {
              string mapId = reader.GetValue(mapIdColumn).ToString();

              filteredIds.Remove(mapId);

              if (!targetIds.Contains(mapId))
              {
                targetIds.Add(mapId);
              }
            }
          }
        }

        command.Connection.Dispose();
      }
    }

    if (targetIds.Count > 0)
    {
      // remove the active ID from the targets

      if (_appState.ActiveMapId.Length > 0)
      {
        targetIds.Remove(_appState.ActiveMapId);
      }

      // remove the selection IDs from the targets if necessary

      if (_appState.TargetLayer == _appState.SelectionLayer && _appState.SelectionIds.Count > 0)
      {
        if (_appState.ActiveMapId.Length > 0)
        {
          selectionIds.Remove(_appState.ActiveMapId);
        }

        foreach (string selectionId in _appState.SelectionIds)
        {
          targetIds.Remove(selectionId);
        }
      }
    }
  }
开发者ID:ClaireBrill,项目名称:GPV,代码行数:78,代码来源:MapMaker.cs


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