本文整理汇总了C#中System.Collections.Hashtable.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.ContainsKey方法的具体用法?C# Hashtable.ContainsKey怎么用?C# Hashtable.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadConfig
/// <summary>
/// Read a simple config file and returns its variables as a Hashtable.
/// </summary>
public static Hashtable ReadConfig(string configPath)
{
if (configPath == null) configPath = "";
if (cache.ContainsKey(configPath)) return cache[configPath];
Hashtable config = new Hashtable();
if (File.Exists(configPath))
{
string[] lines = File.ReadAllLines(configPath);
foreach (string line in lines)
{
if (line.StartsWith("#")) continue;
string[] entry = line.Trim().Split(new char[] { '=' }, 2);
if (entry.Length < 2) continue;
config[entry[0].Trim()] = entry[1].Trim();
}
}
// default values
if (!config.ContainsKey("java.home")) config["java.home"] = "";
string args = "-Xmx384m -Dsun.io.useCanonCaches=false";
if (config.ContainsKey("java.args")) args = config["java.args"] as string;
if (args.IndexOf("-Duser.language") < 0)
args += " -Duser.language=en -Duser.region=US";
config["java.args"] = args;
cache[configPath] = config;
return config;
}
示例2: GetPromotionDs
public DataSet GetPromotionDs(Hashtable paramHash)
{
string sql = @"select pm.SysNo,pm.PromotionName,pm.CreateTime,pm.status, su.username as username
from Promotion_Master pm
left join sys_user su on pm.CreateUserSysNo=su.sysno
where 1=1 @DateFrom @DateTo @status @KeyWords ";
if (paramHash.ContainsKey("DateFrom"))
{
sql = sql.Replace("@DateFrom", "and pm.CreateTime>=" + Util.ToSqlString(paramHash["DateFrom"].ToString()));
}
else
{
sql = sql.Replace("@DateFrom", "");
}
if (paramHash.ContainsKey("DateTo"))
{
sql = sql.Replace("@DateTo", "and pm.CreateTime<=" + Util.ToSqlEndDate(paramHash["DateTo"].ToString()));
}
else
{
sql = sql.Replace("@DateTo", "");
}
if (paramHash.ContainsKey("Status"))
{
sql = sql.Replace("@status", "and pm.status=" + Util.ToSqlString(paramHash["Status"].ToString()));
}
else
{
sql = sql.Replace("@status", "");
}
if (paramHash.ContainsKey("KeyWords"))
{
string[] keys = (Util.TrimNull(paramHash["KeyWords"].ToString())).Split(' ');
if (keys.Length == 1)
{
sql = sql.Replace("@KeyWords", "and pm.PromotionName like " + Util.ToSqlLikeString(paramHash["KeyWords"].ToString()));
}
else
{
string t = "";
for (int i = 0; i < keys.Length; i++)
{
t += "and pm.PromotionName like" + Util.ToSqlLikeString(keys[i]);
}
sql = sql.Replace("@KeyWords", t);
}
}
else
{
sql = sql.Replace("@KeyWords", "");
}
if (paramHash == null || paramHash.Count == 0)
sql = sql.Replace("select", "select top 50 ");
sql = sql + "order by pm.sysno desc";
return SqlHelper.ExecuteDataSet(sql);
}
示例3: ZenElementTypes
public ZenElementTypes(Hashtable def)
{
if (def == null) return;
if (def.ContainsKey("empty")) ParseSet(empty, (string)def["empty"]);
if (def.ContainsKey("block_level")) ParseSet(block_level, (string)def["block_level"]);
if (def.ContainsKey("inline_level")) ParseSet(inline_level, (string)def["inline_level"]);
}
示例4: TestCtorDictionarySingle
public void TestCtorDictionarySingle()
{
// No exception
var hash = new Hashtable(new Hashtable(), 1f);
// No exception
hash = new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable()), 1f), 1f), 1f), 1f);
// []test to see if elements really get copied from old dictionary to new hashtable
Hashtable tempHash = new Hashtable();
// this for assumes that MinValue is a negative!
for (long i = long.MinValue; i < long.MinValue + 100; i++)
{
tempHash.Add(i, i);
}
hash = new Hashtable(tempHash, 1f);
// make sure that new hashtable has the elements in it that old hashtable had
for (long i = long.MinValue; i < long.MinValue + 100; i++)
{
Assert.True(hash.ContainsKey(i));
Assert.True(hash.ContainsValue(i));
}
//[]make sure that there are no connections with the old and the new hashtable
tempHash.Clear();
for (long i = long.MinValue; i < long.MinValue + 100; i++)
{
Assert.True(hash.ContainsKey(i));
Assert.True(hash.ContainsValue(i));
}
}
示例5: Dequeue
/// <summary>
/// Get the next item from the queue which is not in the provided exclusion list.
/// Return null if the queue is empty or if there are no qualifying items.
/// </summary>
/// <returns></returns>
public SendParameters Dequeue(Hashtable exclusionList, Guid currentSlide)
{
lock (this) {
ClientQueue bestClient = null;
SendParameters bestMessage = null;
foreach (ClientQueue cq in m_QueueList.Values) {
//Block student messages when sending public messages.
if ((exclusionList.ContainsKey(cq.Id)) && (cq.IsPublicNode) && !((ReferenceCounter)exclusionList[cq.Id]).IsZero)
return cq.Dequeue(currentSlide);
if (m_DisabledClients.ContainsKey(cq.Id))
continue;
if (((exclusionList.ContainsKey(cq.Id)) && (((ReferenceCounter)exclusionList[cq.Id]).IsZero)) ||
(!exclusionList.ContainsKey(cq.Id))) {
SendParameters thisSp = cq.Peek(currentSlide);
if (thisSp != null) {
if (thisSp.CompareTo(bestMessage, currentSlide) < 0) {
bestMessage = thisSp;
bestClient = cq;
}
}
}
}
if (bestClient != null) {
//Trace.WriteLine("Dequeue: best message tag: " + bestMessage.Tags.SlideID.ToString() +
// "; current slide=" + currentSlide.ToString() +
// "; seq number=" + bestMessage.SequenceNumber.ToString(), this.GetType().ToString());
return bestClient.Dequeue(currentSlide);
}
}
return null;
}
示例6: DoExtraProcess
protected override Hashtable DoExtraProcess(Hashtable h)
{
if (!h.Contains("T_SU"))
{
h.Add("T_SU",0);
}
if (!h.ContainsKey("01_SU"))
{
h.Add("01_SU",0);
}
if (!h.ContainsKey("02_SU"))
{
h.Add("02_SU", 0);
}
if (!h.ContainsKey("03_SU"))
{
h.Add("03_SU", 0);
}
if (!h.ContainsKey("04_SU"))
{
h.Add("04_SU", 0);
}
return h;
}
示例7: ImportParticipant
protected void ImportParticipant(EventPageBase ep, string[] participantFields, string[] keys)
{
string email = "";
Hashtable fieldsHashtable = new Hashtable();
if(participantFields.Count() == keys.Count())
for (int i = 0; i < keys.Count(); i++)
{
if(!fieldsHashtable.ContainsKey(keys[i]))
fieldsHashtable.Add(keys[i].ToLower(), participantFields[i]);
}
if (fieldsHashtable.ContainsKey("email"))
email = fieldsHashtable["email"].ToString();
else
return;
if(string.IsNullOrEmpty(email))
return;
XForm xform = ep.RegistrationForm;
XFormData xFormData = xform.CreateFormData();
PopulateChildNodeRecursive(fieldsHashtable, xFormData.Data.ChildNodes);
string xformstring = xFormData.Data.InnerXml;
StatusLiteral.Text += "Adding participant: " + email+"<br/>";
AttendRegistrationEngine.GenerateParticipation(ep.ContentLink, email, false, xformstring,
"Imported participant from text");
}
示例8: Main
static void Main(string[] args)
{
Hashtable hashtable = new Hashtable();
for (int i = 0; i < 1000000; i++)
{
hashtable[i.ToString("0000000")] = i;
}
Stopwatch s1 = Stopwatch.StartNew();
var r1 = hashtable.ContainsKey("09999");
var r2 = hashtable.ContainsKey("30000");
s1.Stop();
Console.WriteLine("{0}", s1.Elapsed);
Dictionary<string, int> dictionary = new Dictionary<string, int>();
for (int i = 0; i < 1000000; i++)
{
dictionary.Add(i.ToString("000000"), i);
}
Stopwatch s2 = Stopwatch.StartNew();
var r3 = dictionary.ContainsKey("09999");
var r4 = dictionary.ContainsKey("30000");
s2.Stop();
Console.WriteLine("{0}", s2.Elapsed);
}
示例9: FileTag
public FileTag(Hashtable options)
{
StatusEvent.FireStatusError(this, statusEvent, Globalisation.GetString(""));
if (options.ContainsKey("Db"))
{
this.Db = (MyDatabase)options["Db"];
}
if (options.ContainsKey("Form"))
{
this.Form = (Form1)options["Form"];
}
if (options.ContainsKey("listview"))
{
this.ListView = (ListView)options["listview"];
this.ListView.MouseDown += new MouseEventHandler(mouseDown_ListView);
this.ListView.OwnerDraw = true;
this.ListView.DrawItem += new DrawListViewItemEventHandler(ListView_DrawItem);
}
if (options.ContainsKey("infopanel"))
{
this.Infopanel = (RichTextBox)options["infopanel"];
}
if (options.ContainsKey("GridFile"))
{
this.GridFile = (GridFile)options["GridFile"];
this.GridFileListView = this.GridFile.GetListView();
//this.GridFileListView.MouseDown += new MouseEventHandler(mouseDown_LoadTag);
this.GridFileListView.SelectedIndexChanged += new System.EventHandler(this.center_listview_SelectedIndexChanged);
}
}
示例10: Dequeue
/// <summary>
/// Get the next item from the queue which is not in the provided exclusion list.
/// Return null if the queue is empty or if there are no qualifying items.
/// </summary>
/// <returns></returns>
public SocketSendParameters Dequeue(Hashtable exclusionList, Guid currentSlide)
{
lock (this) {
SocketQueue bestSocketQueue = null;
SocketSendParameters bestMessage = null;
foreach (SocketQueue sq in m_QueueList.Values) {
if (((exclusionList.ContainsKey(sq.Socket)) && (((ReferenceCounter)exclusionList[sq.Socket]).IsZero)) ||
(!exclusionList.ContainsKey(sq.Socket))) {
SocketSendParameters thisSp = sq.Peek(currentSlide);
if (thisSp != null) {
if (thisSp.CompareTo(bestMessage, currentSlide) < 0) {
bestMessage = thisSp;
bestSocketQueue = sq;
}
}
}
}
if (bestSocketQueue != null) {
//Trace.WriteLine("Dequeue: best message tag: " + bestMessage.Tags.SlideID.ToString() +
// "; current slide=" + currentSlide.ToString() +
// "; seq number=" + bestMessage.SequenceNumber.ToString(), this.GetType().ToString());
return bestSocketQueue.Dequeue(currentSlide);
}
}
return null;
}
示例11: TestGetKeyValueList
public void TestGetKeyValueList()
{
var dic1 = new SortedList();
for (int i = 0; i < 100; i++)
dic1.Add("Key_" + i, "Value_" + i);
var ilst1 = dic1.GetKeyList();
var hsh1 = new Hashtable();
DoIListTests(dic1, ilst1, hsh1, DicType.Key);
Assert.False(hsh1.Count != 2
|| !hsh1.ContainsKey("IsReadOnly")
|| !hsh1.ContainsKey("IsFixedSize"), "Error, KeyList");
dic1 = new SortedList();
for (int i = 0; i < 100; i++)
dic1.Add("Key_" + i, "Value_" + i);
ilst1 = dic1.GetValueList();
hsh1 = new Hashtable();
DoIListTests(dic1, ilst1, hsh1, DicType.Value);
Assert.False(hsh1.Count != 2
|| !hsh1.ContainsKey("IsReadOnly")
|| !hsh1.ContainsKey("IsFixedSize"), "Error, ValueList");
}
示例12: ExecuteRule
/// <summary> Returns a value cast to a specific type
/// *
/// </summary>
/// <param name="aBrc">- The BRERuleContext object
/// </param>
/// <param name="aMap">- The Map of parameters from the XML
/// </param>
/// <param name="aStep">- The step that it is on
/// </param>
/// <returns> The value cast to the specified type
///
/// </returns>
public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep)
{
bool staticCall = false;
if (!aMap.ContainsKey(OBJECTID))
{
if (!aMap.ContainsKey(TYPE))
throw new BRERuleException("Parameter 'Type' or 'ObjectId' not found");
else staticCall = true;
}
if (!aMap.ContainsKey(MEMBER))
{
throw new BRERuleException("Parameter 'Member' not found");
}
else
{
if (staticCall)
return Reflection.ClassCall((string)aMap[TYPE],
(string)aMap[MEMBER],
GetArguments(aMap));
else
return Reflection.ObjectCall(aBrc.GetResult(aMap[OBJECTID]).Result,
(string)aMap[MEMBER],
GetArguments(aMap));
}
}
示例13: FirstNonRepeatedChar
private static char FirstNonRepeatedChar(string str)
{
char[] cArr = str.ToCharArray();
Hashtable h = new Hashtable();
// Build hashtable - Key = Char ; Value = Count (#of times Char occures in string)
for (int i = 0; i < cArr.Length; ++i)
{
if (!h.ContainsKey(cArr[i]))
{
h.Add(cArr[i], 1);
}
else
{
int count = (int)h[cArr[i]];
h[cArr[i]] = count + 1;
}
}
for (int i = 0; i < cArr.Length; ++i)
{
if(h.ContainsKey(cArr[i]))
{
if((int)h[cArr[i]] == 1)
return cArr[i];
}
}
return '0';
}
示例14: Login
public LoginResponse Login (Hashtable request, UserAccount account, IAgentInfo agentInfo, string authType,
string password, out object data)
{
data = null;
string ip = "";
string version = "";
string platform = "";
string mac = "";
string id0 = "";
if (request != null) {
ip = request.ContainsKey ("ip") ? (string)request ["ip"] : "";
version = request.ContainsKey ("version") ? (string)request ["version"] : "";
platform = request.ContainsKey ("platform") ? (string)request ["platform"] : "";
mac = request.ContainsKey ("mac") ? (string)request ["mac"] : "";
id0 = request.ContainsKey ("id0") ? (string)request ["id0"] : "";
}
string message;
if (!m_module.CheckUser (account.PrincipalID, ip,
version,
platform,
mac,
id0, out message)) {
return new LLFailedLoginResponse (LoginResponseEnum.Indeterminant, message, false);
}
return null;
}
示例15: ArgumentParse
/// <summary>
/// Parse arguments.
/// </summary>
/// <param name="args">Argument array from Main() method.</param>
/// <returns>Hashtable of parsed arguments.</returns>
private static Hashtable ArgumentParse(string[] args)
{
Hashtable Return = new Hashtable();
string Key;
bool ReadPort = false;
bool ResetMessage = false;
foreach (String arg in args)
{
if (arg.StartsWith("-") || arg.StartsWith("/"))
{
Key = arg.Substring(1, arg.Length - 1).ToLower();
if (Key.Equals("on"))
{
if (!Return.ContainsKey(PARAMETER_BACKLIGHT))
Return.Add(PARAMETER_BACKLIGHT, true);
}
else if (Key.Equals("off"))
{
if (!Return.ContainsKey(PARAMETER_BACKLIGHT))
Return.Add(PARAMETER_BACKLIGHT, false);
}
else if (Key.StartsWith("p"))
{
if (!Return.ContainsKey(PARAMETER_PORT))
ReadPort = true;
}
ResetMessage = true;
}
else if (ReadPort)
{
Return.Add(PARAMETER_PORT, arg);
ReadPort = false;
}
else
{
if (ResetMessage)
{
if (Return.ContainsKey(PARAMETER_TEXT))
Return.Remove(PARAMETER_TEXT);
ResetMessage = false;
}
if (!Return.ContainsKey(PARAMETER_TEXT))
{
Return.Add(PARAMETER_TEXT, new StringBuilder(arg));
}
else
{
((StringBuilder)Return[PARAMETER_TEXT]).Append(" ").Append(arg);
}
}
}
return Return;
}