本文整理汇总了C#中OrderedDictionary.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.Clear方法的具体用法?C# OrderedDictionary.Clear怎么用?C# OrderedDictionary.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedDictionary
的用法示例。
在下文中一共展示了OrderedDictionary.Clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clear
public void Clear()
{
var dict = new OrderedDictionary<int, int> { { 1, 2 }, { 2, 3 }, { 3, 4 }, { 4, 5 } };
dict.Clear();
Assert.AreEqual(0, dict.Count);
Assert.AreEqual(0, dict.Values.Count);
Assert.IsFalse(dict.ContainsKey(1));
Assert.IsFalse(dict.ContainsValue(2));
}
示例2: Clear
public void Clear()
{
OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();
List<KeyValuePair<string, string>> tracking = new List<KeyValuePair<string, string>>();
KeyValuePair<string, string> one = new KeyValuePair<string, string>("1", "one");
KeyValuePair<string, string> two = new KeyValuePair<string, string>("2", "two");
dictionary.Add(one);
dictionary.Insert(0, two);
Assert.IsTrue(2 == dictionary.Count);
dictionary.Clear();
Assert.IsTrue(0 == dictionary.Count);
}
示例3: PrintC
internal void PrintC(StreamWriterLevel c, string uniqueID)
{
string star = "";
if (!(m_type is IA5StringType))
star = "*";
c.WriteLine();
c.WriteLine("void {0}_Initialize({0}{1} pVal)", uniqueID, star);
c.WriteLine("{");
c.WriteLine();
OrderedDictionary<string, CLocalVariable> localVars = new OrderedDictionary<string, CLocalVariable>();
((ISCCType)m_type).VarsNeededForPrintCInitialize(1, localVars);
CLocalVariable.Print(c, localVars);
((ISCCType)m_type).PrintCInitialize(m_type.PEREffectiveConstraint, m_type.GetOneValidValue(), c, uniqueID, "pVal", 1, 1);
c.WriteLine("}");
c.WriteLine();
//print Constraints aux protypes
foreach (Asn1Type t in m_type.GetMySelfAndAnyChildren<Asn1Type>())
for (int i = 0; i < t.m_constraints.Count; i++)
((ISCConstraint)t.m_constraints[i]).PrintCIsConstraintValidAux(uniqueID + star + " pVal", c);
c.WriteLine();
c.WriteLine("flag {0}_IsConstraintValid(const {0}{1} pVal, int* pErrCode)", uniqueID, star);
c.WriteLine("{");
localVars.Clear();
((ISCCType)m_type).VarsNeededForIsConstraintValid(1, localVars);
CLocalVariable.Print(c, localVars);
((ISCCType)m_type).PrintCIsConstraintValid(m_type.PEREffectiveConstraint, c, uniqueID, uniqueID, "pVal", 1, 1);
c.P(1); c.WriteLine("(void)pVal; /*Dummy statement, just to hide potential warning*/");
c.P(1); c.WriteLine("(void)pErrCode; /*Dummy statement, just to hide potential warning*/");
c.P(1); c.WriteLine("return TRUE;");
c.WriteLine("}");
c.WriteLine();
//print Constraints aux body functions
foreach (Asn1Type t in m_type.GetMySelfAndAnyChildren<Asn1Type>())
for (int i = 0; i < t.m_constraints.Count; i++)
((ISCConstraint)t.m_constraints[i]).PrintCIsConstraintValidAuxBody(c);
c.WriteLine("flag {0}_Encode(const {0}{1} pVal, BitStream* pBitStrm, int* pErrCode, flag bCheckConstraints)", uniqueID, star);
c.WriteLine("{");
localVars.Clear();
((ISCCType)m_type).VarsNeededForEncode(m_type.PEREffectiveConstraint, 1, localVars);
CLocalVariable.Print(c, localVars);
c.P(1); c.WriteLine("if (bCheckConstraints && !{0}_IsConstraintValid(pVal, pErrCode))", uniqueID);
c.P(2); c.WriteLine("return FALSE;");
((ISCCType)m_type).PrintCEncode(m_type.PEREffectiveConstraint, c, uniqueID, "pVal", 1);
c.P(1); c.WriteLine("return TRUE;");
c.WriteLine("}");
c.WriteLine();
c.WriteLine("flag {0}_Decode({0}{1} pVal, BitStream* pBitStrm, int* pErrCode)", uniqueID, star);
c.WriteLine("{");
localVars.Clear();
((ISCCType)m_type).VarsNeededForDecode(m_type.PEREffectiveConstraint, 1, localVars);
CLocalVariable.Print(c, localVars);
((ISCCType)m_type).PrintCDecode(m_type.PEREffectiveConstraint, c, "pVal", 1);
c.P(1); c.WriteLine("return TRUE;");
c.WriteLine("}");
c.WriteLine();
/*
c.WriteLine("void {0}_PrintXml({0}{1} pVal, FILE* fp)", uniqueID, star);
c.WriteLine("{");
c.P(1);
c.Write("fprintf(fp,\"<{0}>\"", m_name);
c.P(1);
c.Write("fprintf(fp,\"</{0}>\"", m_name);
c.WriteLine("}");
c.WriteLine();
*/
}
示例4: Values_Count
public void Values_Count()
{
var dict = new OrderedDictionary<string, int> { { "1", 2 }, { "2", 3 }, { "3", 4 } };
Assert.AreEqual(3, dict.Values.Count);
dict.Add("4", 5);
dict.Add("5", 6);
Assert.AreEqual(5, dict.Values.Count);
dict.Clear();
Assert.AreEqual(0, dict.Values.Count);
}
示例5: ItemEnumeration
public void ItemEnumeration()
{
OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();
List<KeyValuePair<string, string>> tracking = new List<KeyValuePair<string, string>>();
KeyValuePair<string, string> one = new KeyValuePair<string, string>("1", "one");
KeyValuePair<string, string> two = new KeyValuePair<string, string>("2", "two");
int i = 0;
{ // round 1
dictionary.Add(one);
dictionary.Insert(0, two);
// test implicit pairs order
foreach (KeyValuePair<string, string> item in dictionary)
{
switch (i)
{
case 0:
Assert.AreEqual("2", dictionary[i].Key);
break;
case 1:
Assert.AreEqual("1", dictionary[i].Key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
// test explicit pairs order
i = 0;
foreach (KeyValuePair<string, string> item in dictionary.GetOrderedPairs())
{
switch (i)
{
case 0:
Assert.AreEqual("2", dictionary[i].Key);
break;
case 1:
Assert.AreEqual("1", dictionary[i].Key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
// test keys order
i = 0;
foreach (string key in dictionary.GetOrderedKeys())
{
switch (i)
{
case 0:
Assert.AreEqual("2", key);
break;
case 1:
Assert.AreEqual("1", key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
// test values order
i = 0;
foreach (string key in dictionary.GetOrderedValues())
{
switch (i)
{
case 0:
Assert.AreEqual("two", key);
break;
case 1:
Assert.AreEqual("one", key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
}
dictionary.Clear();
Assert.AreEqual(0, dictionary.Count);
i = 0;
{ // round 2
dictionary.Add(one);
dictionary.Add(two);
//.........这里部分代码省略.........