本文整理汇总了C#中Hashtable.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.Remove方法的具体用法?C# Hashtable.Remove怎么用?C# Hashtable.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: h_set_Value
public static object h_set_Value(Hashtable h, String _key, String _value)
{
h.Remove(_key);
h.Add(_key, _value);
return h;
}
示例2: TraverseChildren
public override void TraverseChildren(IBlockStatement block) {
Contract.Assume(block is BlockStatement);
var decompiledBlock = (BlockStatement)block;
var statements = decompiledBlock.Statements;
for (int i = 0; i < statements.Count-3; i++) {
var gotoCondition = statements[i] as GotoStatement;
if (gotoCondition == null) continue;
var gotosThatTarget = this.gotosThatTarget[(uint)gotoCondition.TargetStatement.Label.UniqueKey];
Contract.Assume(gotosThatTarget != null && gotosThatTarget.Count >= 1);
if (gotosThatTarget.Count != 1) continue;
var conditionalGotoBody = LookForCondition(statements, i+1, gotoCondition.TargetStatement);
if (conditionalGotoBody == null || !(conditionalGotoBody.FalseBranch is EmptyStatement)) continue;
var gotoBody = conditionalGotoBody.TrueBranch as GotoStatement;
if (gotoBody == null) continue;
Contract.Assume(i < statements.Count-3);
if (!IsOrContainsAsFirstStatement(statements[i+1], gotoBody.TargetStatement)) continue;
gotosThatTarget.Remove(gotoCondition);
gotosThatTarget = this.gotosThatTarget[(uint)gotoBody.TargetStatement.Label.UniqueKey];
Contract.Assume(gotosThatTarget != null && gotosThatTarget.Count >= 1);
gotosThatTarget.Remove(gotoBody);
var loopBody = ExtractBlock(statements, i+1, gotoCondition.TargetStatement);
var whileLoop = new WhileDoStatement() { Body = loopBody, Condition = conditionalGotoBody.Condition };
Contract.Assume(i < statements.Count);
statements[i] = whileLoop;
}
base.TraverseChildren(block);
}
示例3: ugly
public static long ugly(int max)
{
ArrayList uglies = new ArrayList();
long counter = 1;
Hashtable dict = new Hashtable();
dict[counter] = new long[] { 0, 0, 0 };
while (uglies.Count < max)
{
uglies.Add(counter);
long[] array = (long[])dict[counter];
long x = array[0];
long y = array[1];
long z = array[2];
dict[value(x+1, y, z)] = new long[] { x+1, y, z };
dict[value(x, y+1, z)] = new long[] { x, y+1, z };
dict[value(x, y, z+1)] = new long[] { x, y, z+1 };
dict.Remove(counter);
ArrayList keys = new ArrayList(dict.Keys);
keys.Sort();
counter = (long)keys[0];
}
return (long)uglies[uglies.Count-1];
}
示例4: DeleteKey
public void DeleteKey()
{
Hashtable<string, int> phonebook = new Hashtable<string, int>(100);
phonebook.Add("Razvan Hidan", 0744596712);
phonebook.Add("Ionut Marin", 076653421);
phonebook.Add("Bogdan Dragos", 07111111);
phonebook.Add("Maria Marioara", 0783442);
phonebook.Add("Ana Blandiana", 09883773);
phonebook.Add("Mihai Eminescu", 0038874);
phonebook.Remove("Razvan Hidan");
phonebook.ContainsKey("Razvan Hidan").ShouldBeFalse();
phonebook.Remove("Maria Marioara");
phonebook.ContainsKey("Maria Marioara").ShouldBeFalse();
phonebook.Remove("Mihai Eminescu");
phonebook.ContainsKey("Mihai Eminescu").ShouldBeFalse();
}
示例5: 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);
}
示例6: runTest
public 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";
String strValue;
Hashtable dic1;
try
{
do
{
strLoc = "Loc_8345vdfv";
dic1 = new Hashtable();
for(int i=0; i<10; i++)
{
strValue = "String_" + i;
dic1.Add(i, strValue);
}
iCountTestcases++;
for(int i=0; i<10; i++)
{
if(!dic1.Contains(i))
{
iCountErrors++;
Console.WriteLine("Err_561dvs_" + i + "! Expected value not returned, " + dic1.Contains(i));
}
}
iCountTestcases++;
if(dic1.IsReadOnly)
{
iCountErrors++;
Console.WriteLine("Err_65323gdfgb! Expected value not returned, " + dic1.IsReadOnly);
}
dic1.Remove(0);
iCountTestcases++;
if(dic1.Contains(0))
{
iCountErrors++;
Console.WriteLine("Err_65323gdfgb! Expected value not returned, " + dic1.Contains(0));
}
} while (false);
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! 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;
}
}
示例7: TestHashTableAddRemove
public void TestHashTableAddRemove() {
Hashtable h = new Hashtable();
// these keys produces equal hashkeys
string [] keys = { "lcu.long_name_one", "lcu.long_name_two", "lcu.long_three" };
h.Add( keys[0], "Value Of 1" );
h.Add( keys[1], "Value Of 2" );
h.Add( keys[2], "Value Of 3" );
AssertEquals( "count", 3, h.Count );
h.Remove( keys[0] );
h.Remove( keys[1] );
h.Remove( keys[2] );
AssertEquals( "count", 0, h.Count );
}
示例8: TestContainKeyBasic
public void TestContainKeyBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
Hashtable ht1 = null;
string s1 = null;
string s2 = null;
int i = 0;
ht1 = new Hashtable(); //default constructor
Assert.False(ht1.ContainsKey("No_Such_Key"));
// add few key-val pairs
ht1 = new Hashtable();
for (i = 0; i < 100; i++)
{
sblMsg = new StringBuilder(99);
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg = new StringBuilder(99);
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
ht1.Add(s1, s2);
}
for (i = 0; i < ht1.Count; i++)
{
sblMsg = new StringBuilder(99);
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
Assert.True(ht1.ContainsKey(s1));
}
//
// [] Remove a key and then check
//
sblMsg = new StringBuilder(99);
sblMsg.Append("key_50");
s1 = sblMsg.ToString();
ht1.Remove(s1); //removes "Key_50"
//check whether the key is removed or not
Assert.False(ht1.ContainsKey(s1));
}
示例9: TestCloneBasic
public void TestCloneBasic()
{
Hashtable hsh1;
Hashtable hsh2;
string strKey;
string strValue;
//[] empty Hashtable clone
hsh1 = new Hashtable();
hsh2 = (Hashtable)hsh1.Clone();
Assert.Equal(0, hsh2.Count);
Assert.False(hsh2.IsReadOnly, "Error, Expected value not returned, <<" + hsh1.IsReadOnly + ">> <<" + hsh2.IsReadOnly + ">>");
Assert.False(hsh2.IsSynchronized, "Error, Expected value not returned, <<" + hsh1.IsSynchronized + ">> <<" + hsh2.IsSynchronized + ">>");
//[] Clone should exactly replicate a collection to another object reference
//afterwards these 2 should not hold the same object references
hsh1 = new Hashtable();
for (int i = 0; i < 10; i++)
{
strKey = "Key_" + i;
strValue = "string_" + i;
hsh1.Add(strKey, strValue);
}
hsh2 = (Hashtable)hsh1.Clone();
for (int i = 0; i < 10; i++)
{
strValue = "string_" + i;
Assert.True(strValue.Equals((string)hsh2["Key_" + i]), "Error, Expected value not returned, " + strValue);
}
//now we remove an object from the original list
hsh1.Remove("Key_9");
Assert.Equal(hsh1["Key_9"], null);
strValue = "string_" + 9;
Assert.True(strValue.Equals((string)hsh2["Key_9"]), "Error, Expected value not returned, <<" + hsh1[9] + ">>");
//[]now we try other test cases
//are all the 'other' properties of the Hashtable the same?
hsh1 = new Hashtable(1000);
hsh2 = (Hashtable)hsh1.Clone();
Assert.Equal(hsh1.Count, hsh2.Count);
Assert.Equal(hsh1.IsReadOnly, hsh2.IsReadOnly);
Assert.Equal(hsh1.IsSynchronized, hsh2.IsSynchronized);
}
示例10: Add
public void Add(Hashtable table)
{
foreach (var iteration in Benchmark.Iterations)
{
using (iteration.StartMeasurement())
{
table.Add("key1", "value"); table.Add("key2", "value"); table.Add("key3", "value");
table.Add("key4", "value"); table.Add("key5", "value"); table.Add("key6", "value");
table.Add("key7", "value"); table.Add("key8", "value"); table.Add("key9", "value");
}
for (int i = 1; i <= 9; i++)
table.Remove("key" + i);
}
}
示例11: GetItem
public void GetItem(Hashtable table)
{
object result;
string key = PerfUtils.CreateString(50);
table.Add(key, "value");
foreach (var iteration in Benchmark.Iterations)
{
using (iteration.StartMeasurement())
{
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
}
}
table.Remove(key);
}
示例12: Main
static void Main(string[] args){
int n = 1;
int count = 0;
Random rnd = new Random (42);
Stopwatch st = new Stopwatch ();
if (args.Length > 0) n = Int32.Parse(args[0]);
int[] v = new int [n];
for (int i = 0; i < n; i++)
v [i] = i;
/* Shuffle */
for (int i = n - 1; i > 0; i--) {
int t, pos;
pos = rnd.Next () % i;
t = v [i];
v [i] = v [pos];
v [pos] = t;
}
Hashtable table = new Hashtable (n);
st.Start ();
for (int i = 0; i < n; i++)
table.Add (v [i], v [i]);
for (int i = 0; i < n; i++)
table.Remove (v [i]);
for (int i = n - 1; i >= 0; i--)
table.Add (v [i], v [i]);
st.Stop ();
Console.WriteLine ("Addition {0}", st.ElapsedMilliseconds);
st.Reset ();
st.Start ();
for (int j = 0; j < 8; j++) {
for (int i = 0; i < n; i++) {
if (table.ContainsKey (v [i]))
count++;
}
}
st.Stop ();
Console.WriteLine ("Lookup {0} - Count {1}", st.ElapsedMilliseconds, count);
}
示例13: Main
/*
public static void Main (string [] args)
{
if (args.Length < 2) {
Console.Error.WriteLine ("Usage: xmldocdiff [reference_output.xml] [actual_output.xml]");
return;
}
if (args.Length > 2 && args [2].EndsWith ("-debug"))
debug = true;
try {
Run (args[0], args[1]);
} catch (Exception ex) {
Console.WriteLine ("FAIL: " + args [1]);
throw ex;
}
Console.WriteLine ("PASS: " + args [1]);
}
*/
public static void Compare (string reference, string output)
{
XmlDocument doc1 = new XmlDocument ();
doc1.Load (reference);
XmlDocument doc2 = new XmlDocument ();
doc2.Load (output);
XmlNodeList memberList1 = doc1.SelectNodes ("/doc/members/member");
XmlNodeList memberList2 = doc2.SelectNodes ("/doc/members/member");
Hashtable namedItems = new Hashtable ();
foreach (XmlElement el in memberList1)
namedItems.Add (el.GetAttribute ("name"), el);
foreach (XmlElement el2 in memberList2) {
string name = el2.GetAttribute ("name");
XmlElement el1 = namedItems [name] as XmlElement;
if (el1 == null) {
Report ("Extraneous element found. Name is '{0}'", name);
continue;
}
namedItems.Remove (name);
CompareNodes (el1, el2);
}
foreach (string name in namedItems.Keys)
Report ("Expected comment was not found. Name is {0}, XML is {1}", name, ((XmlElement) namedItems [name]).OuterXml);
// finally, check other nodes than members
doc1.SelectSingleNode ("/doc/members").RemoveAll ();
doc2.SelectSingleNode ("/doc/members").RemoveAll ();
string xml1 = doc1.OuterXml.Replace ("\r", "").Trim ();
string xml2 = doc2.OuterXml.Replace ("\r", "").Trim ();
if (xml1 != xml2)
Report (@"Either of doc, assembly, name, members elements are different.
doc1: {0}
doc2: {1}", xml1, xml2);
}
示例14: GetItem
public void GetItem(Hashtable table)
{
// Setup - utils needs a specific seed to prevent key collision with TestData
object result;
PerfUtils utils = new PerfUtils(983452);
string key = utils.CreateString(50);
table.Add(key, "value");
foreach (var iteration in Benchmark.Iterations)
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < 40000; i++)
{
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
}
}
}
table.Remove(key);
}
示例15: TestGetIsReadOnlyBasic
public void TestGetIsReadOnlyBasic()
{
string strValue;
Hashtable dic1;
//[] Vanila test case - Hashtable doesnt have means of getting a readonly HT
dic1 = new Hashtable();
for (int i = 0; i < 10; i++)
{
strValue = "string_" + i;
dic1.Add(i, strValue);
}
for (int i = 0; i < 10; i++)
{
Assert.True(dic1.Contains(i));
}
Assert.False(dic1.IsReadOnly);
//we'll make sure by doing a modifiable things!!
dic1.Remove(0);
Assert.False(dic1.Contains(0));
}