本文整理汇总了C#中System.Collections.Hashtable.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.Remove方法的具体用法?C# Hashtable.Remove怎么用?C# Hashtable.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NonEmptyDictionary
public void NonEmptyDictionary()
{
Hashtable map = new Hashtable();
map.Add(1, "one");
map.Add(2, "two");
map.Add(3, "three");
ArrayList entryList = new ArrayList(DictionaryHelper.GetEntries(map));
Assert.AreEqual(3, entryList.Count);
DictionaryEntry first = Shift(entryList);
Assert.AreEqual(first.Value, map[first.Key]);
map.Remove(first.Key);
DictionaryEntry second = Shift(entryList);
Assert.AreEqual(second.Value, map[second.Key]);
map.Remove(second.Key);
DictionaryEntry third = Shift(entryList);
Assert.AreEqual(third.Value, map[third.Key]);
map.Remove(third.Key);
Assert.AreEqual(0, map.Count);
Assert.AreEqual(0, entryList.Count);
}
示例2: GetSumPairs0
private static Hashtable GetSumPairs0(int[] input, int sum)
{
Hashtable result = new Hashtable();
foreach (int val in input)
{
if (!result.Contains(val))
{
result.Add(val, sum - val);
}
}
for (int i = 0; i < input.Length - 1; i++)
{
int numb1 = input[i]; //how to remove dup key?
int numb2 = sum - numb1;
if (result.Contains(numb1) && result.Contains(numb2))
{
result.Remove(numb2);
result[numb1] = numb2;
}
else if (result.Contains(numb1) && !result.Contains(numb2))
{
result.Remove(numb1);
}
}
return result;
}
示例3: GenerateGraph
/// <summary>
/// Creates a new Voronoi Graph given a set of Points
/// </summary>
/// <param name="Datapoints">Data points to base the Voronoi Graph around</param>
/// <returns></returns>
public static VoronoiGraph GenerateGraph(IEnumerable Datapoints)
{
BinaryPriorityQueue PQ = new BinaryPriorityQueue();
Hashtable CurrentCircles = new Hashtable();
VoronoiGraph Graph = new VoronoiGraph();
VNode RootNode = null;
foreach (Vector2 V in Datapoints)
{
PQ.Push(new VDataEvent(V));
}
while (PQ.Count > 0)
{
VEvent VE = PQ.Pop() as VEvent;
VDataNode[] CircleCheckList;
if (VE is VDataEvent)
{
RootNode = VNode.ProcessDataEvent(VE as VDataEvent, RootNode, Graph, VE.Y, out CircleCheckList);
}
else if (VE is VCircleEvent)
{
CurrentCircles.Remove(((VCircleEvent)VE).NodeN);
if (!((VCircleEvent)VE).Valid)
continue;
RootNode = VNode.ProcessCircleEvent(VE as VCircleEvent, RootNode, Graph, VE.Y, out CircleCheckList);
}
else throw new Exception("Got event of type " + VE.GetType().ToString() + "!");
foreach (VDataNode VD in CircleCheckList)
{
if (CurrentCircles.ContainsKey(VD))
{
((VCircleEvent)CurrentCircles[VD]).Valid = false;
CurrentCircles.Remove(VD);
}
VCircleEvent VCE = VNode.CircleCheckDataNode(VD, VE.Y);
if (VCE != null)
{
PQ.Push(VCE);
CurrentCircles[VD] = VCE;
}
}
if (VE is VDataEvent)
{
Vector2 DP = ((VDataEvent)VE).DataPoint;
foreach (VCircleEvent VCE in CurrentCircles.Values)
{
if (Vector2.Distance(DP, VCE.Center) < VCE.Y - VCE.Center.y && Math.Abs(Vector2.Distance(DP, VCE.Center) - (VCE.Y - VCE.Center.y)) > 1e-10)
VCE.Valid = false;
}
}
}
return Graph;
}
示例4: A_TestBasicOps
public void A_TestBasicOps()
{
IDictionary weakHashTable = TestWeakHashTableBehavior.CreateDictionary();// new SupportClass.TjWeakHashTable();
Hashtable realHashTable = new Hashtable();
SmallObject[] so = new SmallObject[100];
for (int i = 0; i < 20000; i++)
{
SmallObject key = new SmallObject(i);
SmallObject value = key;
so[i / 200] = key;
realHashTable.Add(key, value);
weakHashTable.Add(key, value);
}
Assert.AreEqual(weakHashTable.Count, realHashTable.Count);
ICollection keys = (ICollection)realHashTable.Keys;
foreach (SmallObject key in keys)
{
Assert.AreEqual(((SmallObject)realHashTable[key]).i,
((SmallObject)weakHashTable[key]).i);
Assert.IsTrue(realHashTable[key].Equals(weakHashTable[key]));
}
ICollection values1 = (ICollection)weakHashTable.Values;
ICollection values2 = (ICollection)realHashTable.Values;
Assert.AreEqual(values1.Count, values2.Count);
realHashTable.Remove(new SmallObject(10000));
weakHashTable.Remove(new SmallObject(10000));
Assert.AreEqual(weakHashTable.Count, 20000);
Assert.AreEqual(realHashTable.Count, 20000);
for (int i = 0; i < so.Length; i++)
{
realHashTable.Remove(so[i]);
weakHashTable.Remove(so[i]);
Assert.AreEqual(weakHashTable.Count, 20000 - i - 1);
Assert.AreEqual(realHashTable.Count, 20000 - i - 1);
}
//After removals, compare the collections again.
ICollection keys2 = (ICollection)realHashTable.Keys;
foreach (SmallObject o in keys2)
{
Assert.AreEqual(((SmallObject)realHashTable[o]).i,
((SmallObject)weakHashTable[o]).i);
Assert.IsTrue(realHashTable[o].Equals(weakHashTable[o]));
}
}
示例5: deleteTestOfHashtable
public void deleteTestOfHashtable()
{
Hashtable oTable = new Hashtable();
oTable.Add("test", "testing");
oTable.Remove("test");
Assert.IsNull(oTable["test"]);
}
示例6: UpdateFromSelection
public void UpdateFromSelection (Photo [] sel)
{
Hashtable taghash = new Hashtable ();
for (int i = 0; i < sel.Length; i++) {
foreach (Tag tag in sel [i].Tags) {
int count = 1;
if (taghash.Contains (tag))
count = ((int) taghash [tag]) + 1;
if (count <= i)
taghash.Remove (tag);
else
taghash [tag] = count;
}
if (taghash.Count == 0)
break;
}
selected_photos_tagnames = new ArrayList ();
foreach (Tag tag in taghash.Keys)
if ((int) (taghash [tag]) == sel.Length)
selected_photos_tagnames.Add (tag.Name);
Update ();
}
示例7: GetConverter
public static TypeConverter GetConverter(Type itemType)
{
TypeConverter converter = TypeDescriptor.GetConverter(itemType);
if (converter == null || converter.GetType() == typeof(TypeConverter))
{
// We got an invalid converter. WPF will do this if the converter
// is internal, but we use internal converters all over the place
// at design time. Detect this and build the converter ourselves.
if (converterCache != null)
{
converter = (TypeConverter)converterCache[itemType];
if (converter != null)
{
return converter;
}
}
AttributeCollection attrs = TypeDescriptor.GetAttributes(itemType);
TypeConverterAttribute tca = attrs[typeof(TypeConverterAttribute)] as TypeConverterAttribute;
if (tca != null && tca.ConverterTypeName != null)
{
Type type = Type.GetType(tca.ConverterTypeName);
if (type != null && !type.IsPublic && typeof(TypeConverter).IsAssignableFrom(type))
{
ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(Type) });
if (ctor != null)
{
converter = (TypeConverter)ctor.Invoke(new object[] { itemType });
}
else
{
converter = (TypeConverter)Activator.CreateInstance(type);
}
lock (converterCacheSyncObject)
{
if (converterCache == null)
{
converterCache = new Hashtable();
// Listen to type changes and clear the cache.
// This allows new metadata tables to be installed
TypeDescriptor.Refreshed += delegate(RefreshEventArgs args)
{
converterCache.Remove(args.TypeChanged);
};
}
converterCache[itemType] = converter;
}
}
}
}
return converter;
}
示例8: TestAddRemoveLargeAmountNumbers
public void TestAddRemoveLargeAmountNumbers()
{
Hashtable ht = new Hashtable();
//[] Read all of the doubles from the file and store them into the hashtable
int count = 0;
foreach (var number in s_AddStressInputData)
{
ht.Add(number, count++);
}
//[] Read all of the doubles from the file and make sure they exist in the hashtable hashtable
count = 0;
foreach (var tempLong in s_AddStressInputData)
{
Assert.Equal((int)ht[tempLong], count);
Assert.True(ht.ContainsKey(tempLong));
++count;
}
//[] Remove all of the entries
foreach (var tempLong in s_AddStressInputData)
{
ht.Remove(tempLong);
}
Assert.Equal(0, ht.Count);
}
示例9: ToText
public override string ToText(Subtitle subtitle, string title)
{
// timestamp: 00:00:01:401, filepos: 000000000
const string paragraphWriteFormat = "timestamp: {0}, filepos: {1}";
var tempNonTimeCodes = new Hashtable();
foreach (DictionaryEntry de in (subtitle.OriginalFormat as Idx).NonTimeCodes)
{
tempNonTimeCodes.Add(de.Key, de.Value);
}
var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs)
{
var removeList = new List<int>();
foreach (DictionaryEntry de in tempNonTimeCodes)
{
if (Convert.ToInt32(de.Key) < Convert.ToInt32(p.Text))
{
sb.AppendLine(de.Value.ToString());
removeList.Add(Convert.ToInt32(de.Key));
}
}
foreach (int key in removeList)
tempNonTimeCodes.Remove(key);
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartTime, p.Text));
}
foreach (DictionaryEntry de in tempNonTimeCodes)
sb.AppendLine(de.Value.ToString());
return sb.ToString().Trim();
}
示例10: Main_7_9_5
//Main_7_9_5
public static void Main_7_9_5()
{
Hashtable ht = new Hashtable();
//��Ӽ���Ԫ��
ht.Add("Name", "��");
ht.Add("Age", 27);
ht.Add("Degree", "˶ʿ");
//�Լ�ֵ���Ҽ���
Console.WriteLine("{0}��������{1}", ht["Name"], ht["Age"]);
//���ϱ���
foreach (DictionaryEntry de in ht)
{
Console.WriteLine("{0}--{1}", de.Key.ToString(), de.Value.ToString());
}
//ɾ������Ԫ��
ht.Remove("Age");
//��������
ArrayList als = new ArrayList(ht.Keys);
als.Sort();
foreach (string key in als)
{
Console.WriteLine("{0}--{1}", key, ht[key].ToString());
}
//�������
ht.Clear();
}
示例11: Main
static void Main(string[] args)
{
Hashtable openWith = new Hashtable();
String key = " ";
while (key != "")
{
int value = 1;
key = Console.ReadLine();
if (openWith.Contains(key))
{
int value1 = (int)openWith[key];
openWith[key] = ++value1;
}
else
openWith.Add(key, value);
}
openWith.Remove("");
PrintValues(openWith);
Console.ReadKey();
}
示例12: GetNamespacesToRender
internal override void GetNamespacesToRender(XmlElement element, SortedList attrListToRender, SortedList nsListToRender, Hashtable nsLocallyDeclared)
{
XmlAttribute a = null;
object[] array = new object[nsLocallyDeclared.Count];
nsLocallyDeclared.Values.CopyTo(array, 0);
foreach (object obj2 in array)
{
int num;
a = (XmlAttribute) obj2;
XmlAttribute nearestRenderedNamespaceWithMatchingPrefix = base.GetNearestRenderedNamespaceWithMatchingPrefix(Utils.GetNamespacePrefix(a), out num);
if (Utils.IsNonRedundantNamespaceDecl(a, nearestRenderedNamespaceWithMatchingPrefix))
{
nsLocallyDeclared.Remove(Utils.GetNamespacePrefix(a));
if (Utils.IsXmlNamespaceNode(a))
{
attrListToRender.Add(a, null);
}
else
{
nsListToRender.Add(a, null);
}
}
}
for (int i = base.m_ancestorStack.Count - 1; i >= 0; i--)
{
foreach (object obj3 in base.GetScopeAt(i).GetUnrendered().Values)
{
a = (XmlAttribute) obj3;
if (a != null)
{
this.GetNamespaceToRender(Utils.GetNamespacePrefix(a), attrListToRender, nsListToRender, nsLocallyDeclared);
}
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:C14NAncestralNamespaceContextManager.cs
示例13: RemoveDup
static void RemoveDup(ref Hashtable target,
Hashtable dup)
{
if (dup.Count == 0)
return;
ICollection array = target.Keys;
int nOldCount = array.Count;
ArrayList aWantRemove = new ArrayList();
foreach(object strKey in array)
{
if (dup.Contains(strKey) == true)
{
aWantRemove.Add(strKey);
}
}
for(int i=0;i<aWantRemove.Count;i++)
{
target.Remove(aWantRemove[i]);
// Debug.Assert(nOldCount == array.Count, "Hashtable.Keys不是只读的?");
}
}
示例14: GatherNamespaceToRender
private void GatherNamespaceToRender(string nsPrefix, SortedList nsListToRender, Hashtable nsLocallyDeclared)
{
int num;
foreach (object obj2 in nsListToRender.GetKeyList())
{
if (Utils.HasNamespacePrefix((XmlAttribute) obj2, nsPrefix))
{
return;
}
}
XmlAttribute a = (XmlAttribute) nsLocallyDeclared[nsPrefix];
XmlAttribute nearestRenderedNamespaceWithMatchingPrefix = base.GetNearestRenderedNamespaceWithMatchingPrefix(nsPrefix, out num);
if (a != null)
{
if (Utils.IsNonRedundantNamespaceDecl(a, nearestRenderedNamespaceWithMatchingPrefix))
{
nsLocallyDeclared.Remove(nsPrefix);
nsListToRender.Add(a, null);
}
}
else
{
int num2;
XmlAttribute nearestUnrenderedNamespaceWithMatchingPrefix = base.GetNearestUnrenderedNamespaceWithMatchingPrefix(nsPrefix, out num2);
if (((nearestUnrenderedNamespaceWithMatchingPrefix != null) && (num2 > num)) && Utils.IsNonRedundantNamespaceDecl(nearestUnrenderedNamespaceWithMatchingPrefix, nearestRenderedNamespaceWithMatchingPrefix))
{
nsListToRender.Add(nearestUnrenderedNamespaceWithMatchingPrefix, null);
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:ExcAncestralNamespaceContextManager.cs
示例15: LinerComplex
public static int LinerComplex(string str)
{
Hashtable T = new Hashtable () ;
Hashtable B = new Hashtable () ;
Hashtable C = new Hashtable () ;
C .Add (0,1) ;
B .Add (0,1) ;
int m = -1 , N = 0 , L = 0 ; //上述步骤完成初始化
while (N < str.Length )
{ //计算离差
int d = str [N ] == '0' ? 0 : 1 ;
int i = 1 ;
#region
while (i <= L )
{
if (C .ContainsKey (i ))
{
if (str [N-i ] == '1')
d += 1 ; //则ci = 1
}
i++ ;
}
d = d % 2;
if ( d ==1 )
{
T = (Hashtable )C.Clone() ;
foreach (DictionaryEntry k in B )
{
if ((int )k .Value == 1)
{
int temp = (int )k .Key + N - m ;
if (C .ContainsKey (temp ))
{
C .Remove (temp ) ;
}
else
{
C .Add (temp ,1 ) ;
}
}
}
if (L <= (int )Math .Floor (N *0.5) )
{
L = N +1 -L ;
m = N ;
B =(Hashtable ) T.Clone() ;
}
}
#endregion
// Console.Write("L = {0} ;", L);
// foreach (DictionaryEntry j in C )
// {
// Console.Write( j.Key +" ;");
// }
// Console.WriteLine();
N ++ ;
}
return L ;
}