本文整理汇总了C#中System.Collections.Hashtable.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.Contains方法的具体用法?C# Hashtable.Contains怎么用?C# Hashtable.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: isAnagram
public static bool isAnagram(string[] test)
{
Hashtable tmp = new Hashtable();
int count = 0;
foreach (string s in test)
{
if (count == 0)
{
foreach (char c in s)
{
string key = c.ToString();
if (tmp.Contains(key))
{
int value = (int)tmp[key];
tmp[key] = value + 1;
}
else
{
tmp.Add(key, 1);
}
}
}
if (count == 1)
{
foreach (char c in s)
{
string key = c.ToString();
if (!tmp.Contains(key)) return false;
else
{
int value = (int)tmp[key];
if (value - 1 < 0) return false;
tmp[key] = value - 1;
}
}
// at the end, check tmp each value ==0
foreach (DictionaryEntry entry in tmp)
{
int value = (int)entry.Value;
if (value > 0) return false;
// redundant check
if (value < 0)
{
return false; // unreachable code
}
}
return true;
}
count++;
}
return false;
}
示例2: ReadDialog
/// <summary>
/// Constructor for Read dialog
/// </summary>
public ReadDialog(Epi.Windows.MakeView.Forms.MakeViewMainForm frm)
: base(frm)
{
InitializeComponent();
Construct();
SourceProjectNames = new Hashtable();
if (frm.projectExplorer != null)
{
if (frm.projectExplorer.currentPage != null)
{
this.sourceProject = frm.projectExplorer.currentPage.view.Project;
this.selectedProject = this.sourceProject;
this.selectedDataSource = this.selectedProject;
foreach (string s in this.sourceProject.GetNonViewTableNames())
{
string key = s.ToUpper().Trim();
if (!SourceProjectNames.Contains(key))
{
SourceProjectNames.Add(key, true);
}
}
foreach (string s in this.sourceProject.GetViewNames())
{
string key = s.ToUpper().Trim();
if (!SourceProjectNames.Contains(key))
{
SourceProjectNames.Add(key, true);
}
}
}
}
}
示例3: CreateChildControls
protected override void CreateChildControls()
{
Hashtable hs = new Hashtable();
int result = LoginEntity.LoadConfiguration(SPContext.Current.Web.CurrentUser.LoginName, ref hs);
if (result == 1)
{
PlayerUserControl control = (PlayerUserControl)Page.LoadControl(_ascxPath);
if (hs != null)
{
if (hs.Contains("APIKey"))
control.APIKey = hs["APIKey"].ToString();
if (hs.Contains("SecretKey"))
control.SecretKey = hs["SecretKey"].ToString();
}
Controls.Add(control);
}
else
{
string _ascxPathAPI = @"~/_CONTROLTEMPLATES/OoyalaPlugin.WP_API_Settings/APISettings/APISettingsUserControl.ascx";
APISettingsUserControl control = (APISettingsUserControl)Page.LoadControl(_ascxPathAPI);
if (hs != null)
{
if (hs.Contains("APIKey"))
control.APIKey = hs["APIKey"].ToString();
if (hs.Contains("SecretKey"))
control.SecretKey = hs["SecretKey"].ToString();
if (hs.Contains("PartnerCode"))
control.PartnerCode = hs["PartnerCode"].ToString();
}
control.APIErrorMessage = "API Settings are not configured properly";
Controls.Add(control);
return;
}
}
示例4: Load
public static Settings Load(Hashtable settings)
{
var result = new Settings();
if (settings == null)
return result;
if (settings.Contains("RepoOwner"))
result.RepoOwner = settings["RepoOwner"].ToString();
if (settings.Contains("RepoName"))
result.RepoName = settings["RepoName"].ToString();
ReleaseTypes releaseType;
result.ReleaseType = settings.Contains("Releases") && Enum.TryParse(settings["Releases"].ToString(), out releaseType)
? releaseType
: ReleaseTypes.Latest;
result.PreReleaseType = settings.Contains("PreReleases") && Enum.TryParse(settings["PreReleases"].ToString(), out releaseType)
? releaseType
: ReleaseTypes.Latest;
bool boolVal;
result.EnableDownloadCounts = !settings.Contains("EnableDownloadCount") || !bool.TryParse(settings["EnableDownloadCount"].ToString(), out boolVal) || boolVal;
return result;
}
示例5: Two
/*
* Given an array of integers and a target value, find a pair of integers that
* sum to the target value. Time complexity should be O(n).
*/
public static int[] Two(int[] arr, int target)
{
Hashtable hash = new Hashtable();
int iterations = 0;
for (int i = 0; i < arr.Length; i++)
{
if (!hash.Contains(arr[i]))
{
hash.Add(arr[i], arr[i]);
}
int diff = target - arr[i];
if (hash.Contains(diff))
{
return new int[] { arr[i], diff };
}
iterations++;
}
return new int[] { };
}
示例6: CreateDigitalSign
/// <summary>
/// 创建数字签名
/// </summary>
/// <param name="htValidationParams">存放数字签名参数的Hashtable</param>
/// <returns>DigitalSign</returns>
public static string CreateDigitalSign(Hashtable htValidationParams)
{
if (!htValidationParams.Contains("AccountKey")
|| String.IsNullOrWhiteSpace(htValidationParams["AccountKey"].ToString()))
{
throw new ApplicationException("缺少API帐户密钥");
}
string accountKey = htValidationParams["AccountKey"].ToString().Trim(); //API帐户密钥
List<string> stringList = new List<string>();
//if (htValidationParams.Contains("service_version"))
// stringList.Add(string.Format("service_version={0}", htValidationParams["service_version"].ToString()));
if (htValidationParams.Contains("partner"))
stringList.Add(string.Format("partner={0}", htValidationParams["partner"].ToString()));
if (htValidationParams.Contains("user_ip"))
stringList.Add(string.Format("user_ip={0}", htValidationParams["user_ip"].ToString()));
if (htValidationParams.Contains("sign"))
stringList.Add(string.Format("sign={0}", htValidationParams["sign"].ToString()));
//if (htValidationParams.Contains("ReqTime")
// && htValidationParams["ReqTime"] != null)
// stringList.Add(string.Format("ReqTime={0}", ((DateTime)htValidationParams["ReqTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")));
string[] originalArray = stringList.ToArray();
string[] sortedArray = BubbleSort(originalArray);
string digitalSing = GetMD5ByArray(sortedArray, accountKey, "utf-8");
return digitalSing;
}
示例7: numerize
public Example numerize(Hashtable attrValueToNumber)
{
Hashtable numerizedExampleData = new Hashtable();
foreach (string key in attributes.Keys)
{
Attribute attribute = (Attribute)attributes[key];
if ( attribute is StringAttribute)
{
int correspondingNumber = int.Parse(((Hashtable)(attrValueToNumber[key]))[attribute.valueAsString()].ToString());
NumericAttributeSpecification spec = new NumericAttributeSpecification(key);
if (numerizedExampleData.Contains(key))
numerizedExampleData[key] = new NumericAttribute((double)correspondingNumber,spec);
else
numerizedExampleData.Add(key,new NumericAttribute((double)correspondingNumber,spec));
}
else
{//Numeric Attribute
if (numerizedExampleData.Contains(key))
numerizedExampleData[key] = attribute;
else
numerizedExampleData.Add(key,attribute);
}
}
return new Example(numerizedExampleData,(Attribute)numerizedExampleData[targetAttribute.name()]);
}
示例8: 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;
}
示例9: TestContainsBasic
public void TestContainsBasic()
{
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.Contains("No_Such_Key"));
/// [] Testcase: 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.Contains(s1));
}
//
// Remove a key and then check
//
sblMsg = new StringBuilder(99);
sblMsg.Append("key_50");
s1 = sblMsg.ToString();
ht1.Remove(s1); //removes "Key_50"
Assert.False(ht1.Contains(s1));
}
示例10: SetOptions
protected override void SetOptions(Hashtable options)
{
// get the package code - generate if not specified
_packageCode = options.Contains("packagecode")
? new Guid(options["packagecode"].ToString())
: Guid.NewGuid();
// get the product code - set to package code if not specified
_productCode = options.Contains("productcode") ? new Guid(options["productcode"].ToString()) : _packageCode;
// get the upgrade code - leave empty if not specified
if (options.Contains("upgradecode"))
_upgradeCode = new Guid(options["upgradecode"].ToString());
}
示例11: LoadSettings
private void LoadSettings()
{
moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);
itemId = WebUtils.ParseInt32FromQueryString("ItemID", -1);
moduleSettings = ModuleSettings.GetModuleSettings(moduleId);
GmapApiKey = SiteUtils.GetGmapApiKey();
if (moduleSettings.Contains("GoogleMapInitialMapTypeSetting"))
{
string gmType = moduleSettings["GoogleMapInitialMapTypeSetting"].ToString();
try
{
mapType = (MapType)Enum.Parse(typeof(MapType), gmType);
}
catch (ArgumentException) { }
}
GoogleMapHeightSetting = WebUtils.ParseInt32FromHashtable(
moduleSettings, "GoogleMapHeightSetting", GoogleMapHeightSetting);
//GoogleMapWidthSetting = WebUtils.ParseInt32FromHashtable(
// moduleSettings, "GoogleMapWidthSetting", GoogleMapWidthSetting);
if (moduleSettings.Contains("GoogleMapWidthSetting"))
{
GoogleMapWidthSetting = moduleSettings["GoogleMapWidthSetting"].ToString();
}
GoogleMapInitialZoomSetting = WebUtils.ParseInt32FromHashtable(
moduleSettings, "GoogleMapInitialZoomSetting", GoogleMapInitialZoomSetting);
GoogleMapEnableMapTypeSetting = WebUtils.ParseBoolFromHashtable(
moduleSettings, "GoogleMapEnableMapTypeSetting", false);
GoogleMapEnableZoomSetting = WebUtils.ParseBoolFromHashtable(
moduleSettings, "GoogleMapEnableZoomSetting", false);
GoogleMapShowInfoWindowSetting = WebUtils.ParseBoolFromHashtable(
moduleSettings, "GoogleMapShowInfoWindowSetting", false);
GoogleMapEnableLocalSearchSetting = WebUtils.ParseBoolFromHashtable(
moduleSettings, "GoogleMapEnableLocalSearchSetting", false);
GoogleMapEnableDirectionsSetting = WebUtils.ParseBoolFromHashtable(
moduleSettings, "GoogleMapEnableDirectionsSetting", false);
AddClassToBody("eventcaldetail");
}
示例12: SelectExecuteQuery
public Hashtable SelectExecuteQuery(string cultureName)
{
Hashtable hashTable = new Hashtable();
using (IDbConnection dbConnection = this.dataProvider.GetConnection)
{
dbConnection.Open();
string resourceCmdText = "Select ResourceKey, ResourceValue from tStringResource where Language = @cultureName";
List<KeyValuePair<string, object>> resourceParameters = new List<KeyValuePair<string, object>>();
resourceParameters.Add(new KeyValuePair<string, object>("@cultureName", cultureName));
IDbCommand command = this.GetCommand(resourceCmdText, dbConnection, this.dataProvider.GetParameter(resourceParameters), null);
DataTable resourceDataTable = this.dataProvider.SelectQuery(command);
string errorCmdText = "Select ErrorKey, ErrorMessage from tErrorResource where Language = @cultureName";
List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
parameters.Add(new KeyValuePair<string, object>("@cultureName", cultureName));
IDbCommand Errorcommand = this.GetCommand(errorCmdText, dbConnection, this.dataProvider.GetParameter(parameters), null);
DataTable ErrorDataTable = this.dataProvider.SelectQuery(Errorcommand);
if (resourceDataTable != null && resourceDataTable.Rows.Count > 0)
{
foreach (DataRow row in resourceDataTable.Rows)
{
if (hashTable.Contains(row["ResourceKey"].ToString()) == false)
{
hashTable.Add(row["ResourceKey"].ToString(), row["ResourceValue"].ToString());
}
}
}
if (ErrorDataTable != null && ErrorDataTable.Rows.Count > 0)
{
foreach (DataRow row in ErrorDataTable.Rows)
{
if (hashTable.Contains(row["ErrorKey"].ToString()) == false)
{
hashTable.Add(row["ErrorKey"].ToString(), row["ErrorMessage"].ToString());
}
}
}
}
return hashTable;
}
示例13: GetEmpMultiFilterParams
public static ArrayList GetEmpMultiFilterParams(ref string sqlStr, Hashtable hashTable, DBUtil dbUtil)
{
ArrayList listParms = new ArrayList();
UtilService utilService = new UtilService();
if (hashTable.Contains("@EmpName"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@EmpName");
listParms.Add(new SqlParameter("@EmpName", SqlDbType.NVarChar, 40));
}
if (hashTable.Contains("@IdCard"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@IdCard");
listParms.Add(new SqlParameter("@IdCard", SqlDbType.VarChar, 20));
}
if (hashTable.Contains("@DeptID"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@DeptID");
listParms.Add(new SqlParameter("@DeptID", SqlDbType.VarChar, 800));
}
if (hashTable.Contains("@EmpTypeID"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@EmpTypeID");
listParms.Add(new SqlParameter("@EmpTypeID", SqlDbType.VarChar, 800));
}
if (hashTable.Contains("@StatusKBN"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@StatusKBN");
listParms.Add(new SqlParameter("@StatusKBN", SqlDbType.VarChar, 800));
}
if (hashTable.Contains("@EntryTimeStart"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@EntryTimeStart");
listParms.Add(new SqlParameter("@EntryTimeStart", SqlDbType.DateTime));
}
if (hashTable.Contains("@EntryTimeEnd"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@EntryTimeEnd");
listParms.Add(new SqlParameter("@EntryTimeEnd", SqlDbType.DateTime));
}
if (hashTable.Contains("@LeaveTimeStart"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@LeaveTimeStart");
listParms.Add(new SqlParameter("@LeaveTimeStart", SqlDbType.DateTime));
}
if (hashTable.Contains("@LeaveTimeEnd"))
{
sqlStr = utilService.validSearchFilter(sqlStr, "@LeaveTimeEnd");
listParms.Add(new SqlParameter("@LeaveTimeEnd", SqlDbType.DateTime));
}
return listParms;
}
示例14: CheckForComparisonDelegateLoops
private void CheckForComparisonDelegateLoops(String delegateName)
{
String nextDelegateName = delegateName;
Hashtable alreadyReferencedDelegates = new Hashtable();
while(true)
{
ComparisonEvaluator nextComparisonEvaluator =
(ComparisonEvaluator)_comparisonEvaluators[nextDelegateName];
if(nextComparisonEvaluator == null)
{
break;
}
if(alreadyReferencedDelegates.Contains(nextDelegateName))
{
String msg = SR.GetString(SR.DevFiltDict_FoundLoop,
nextComparisonEvaluator.capabilityName,
delegateName);
throw new Exception(msg);
}
alreadyReferencedDelegates[nextDelegateName] = null;
nextDelegateName = nextComparisonEvaluator.capabilityName;
}
}
示例15: 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();
}