本文整理汇总了C#中System.Collections.Dictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ContainsKey方法的具体用法?C# Dictionary.ContainsKey怎么用?C# Dictionary.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFromDictionary
public static NotifyFulfillmentInput CreateFromDictionary(Dictionary<string, object> jsonMap)
{
try
{
if (jsonMap == null)
{
return null;
}
var request = new NotifyFulfillmentInput();
if(jsonMap.ContainsKey("receiptId"))
{
request.ReceiptId = (string) jsonMap["receiptId"];
}
if(jsonMap.ContainsKey("fulfillmentResult"))
{
request.FulfillmentResult = (string) jsonMap["fulfillmentResult"];
}
return request;
}
catch (System.ApplicationException ex)
{
throw new AmazonException("Error encountered while creating Object from dicionary", ex);
}
}
示例2: 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);
}
示例3: TwoSum
public int[] TwoSum(int[] nums, int target)
{
Dictionary<int, int> dictNums = new Dictionary<int, int>();
int[] returnvalue = new int[2] { 0, 0 };
for (int i = 0; i < nums.Length; i++)
{
if (!dictNums.ContainsKey(nums[i]))
{
dictNums.Add(nums[i], i);
}
}
for (int i = 0; i < nums.Length; i++)
{
int Remains = target - nums[i];
if (dictNums.ContainsKey(Remains))
{
int RemainsIndex = dictNums[Remains];
if (i != RemainsIndex)
{
returnvalue[0] = i + 1;
returnvalue[1] = RemainsIndex + 1;
break;
}
}
}
Array.Sort(returnvalue);
return returnvalue;
}
示例4: Start
void Start() {
hoverTrailSet = new HashSet<TrailRenderer>(hoverTrails);
flightTrailSet = new HashSet<TrailRenderer>(flightTrails);
stunTrailSet = new HashSet<TrailRenderer>(stunTrails);
trailTimes = new Dictionary<TrailRenderer, float>();
foreach (TrailRenderer t in hoverTrails) {
if (!trailTimes.ContainsKey(t)) {
trailTimes.Add(t, t.time);
}
}
foreach (TrailRenderer t in flightTrails) {
if (!trailTimes.ContainsKey(t)) {
trailTimes.Add(t, t.time);
}
}
foreach (TrailRenderer t in stunTrails) {
if (!trailTimes.ContainsKey(t)) {
trailTimes.Add(t, t.time);
}
}
hoverTrails = null;
flightTrails = null;
stunTrails = null;
this.mode = PlayerModeManager.PlayerMode.Stun;
SetMode(PlayerModeManager.PlayerMode.Hover);
}
示例5: FillCache
///<summary></summary>
public static void FillCache(DataTable table){
//No need to check RemotingRole; no call to db.
Dictionary<string,Pref> dictPrefs=new Dictionary<string,Pref>();
Pref pref;
//PrefName enumpn;
//Can't use Crud.PrefCrud.TableToList(table) because it will fail the first time someone runs 7.6 before conversion.
List<string> listDuplicatePrefs=new List<string>();
for(int i=0;i<table.Rows.Count;i++) {
pref=new Pref();
if(table.Columns.Contains("PrefNum")) {
pref.PrefNum=PIn.Long(table.Rows[i]["PrefNum"].ToString());
}
pref.PrefName=PIn.String(table.Rows[i]["PrefName"].ToString());
pref.ValueString=PIn.String(table.Rows[i]["ValueString"].ToString());
//no need to load up the comments. Especially since this will fail when user first runs version 5.8.
if(dictPrefs.ContainsKey(pref.PrefName)) {
listDuplicatePrefs.Add(pref.PrefName);//The current preference is a duplicate preference.
}
else {
dictPrefs.Add(pref.PrefName,pref);
}
}
if(listDuplicatePrefs.Count>0 && //Duplicate preferences found, and
dictPrefs.ContainsKey(PrefName.CorruptedDatabase.ToString()) && //CorruptedDatabase preference exists (only v3.4+), and
dictPrefs[PrefName.CorruptedDatabase.ToString()].ValueString!="0") //The CorruptedDatabase flag is set.
{
throw new ApplicationException(Lans.g("Prefs","Your database is corrupted because an update failed. Please contact us. This database is unusable and you will need to restore from a backup."));
}
else if(listDuplicatePrefs.Count>0) {//Duplicate preferences, but the CorruptedDatabase flag is not set.
throw new ApplicationException(Lans.g("Prefs","Duplicate preferences found in database")+": "+String.Join(",",listDuplicatePrefs));
}
PrefC.Dict=dictPrefs;
}
示例6: PerformAnalysis
public void PerformAnalysis(BasicBlocks basicBlocks)
{
// Create dictionary of referenced blocks
Dictionary<BasicBlock, int> referenced = new Dictionary<BasicBlock, int>(basicBlocks.Count);
// Allocate list of ordered Blocks
blockOrder = new BasicBlock[basicBlocks.Count];
int orderBlockCnt = 0;
// Create sorted worklist
var workList = new Stack<BasicBlock>();
foreach (var head in basicBlocks.HeadBlocks)
{
workList.Push(head);
while (workList.Count != 0)
{
var block = workList.Pop();
if (!referenced.ContainsKey(block))
{
referenced.Add(block, 0);
blockOrder[orderBlockCnt++] = block;
foreach (var successor in block.NextBlocks)
if (!referenced.ContainsKey(successor))
workList.Push(successor);
}
}
}
}
示例7: createRoads
// We want to mark different elevation zones so that we can draw
// island-circling roads that divide the areas.
public void createRoads(Map map) {
// Oceans and coastal polygons are the lowest contour zone
// (1). Anything connected to contour level K, if it's below
// elevation threshold K, or if it's water, gets contour level
// K. (2) Anything not assigned a contour level, and connected
// to contour level K, gets contour level K+1.
var queue = new Queue<Center> ();
var elevationThresholds = new float[]{0F, 0.05F, 0.37F, 0.64F};
var cornerContour = new Dictionary<int, int>(); // corner index -> int contour level
var centerContour = new Dictionary<int, int>(); // center index -> int contour level
foreach (Center p in map.centers) {
if (p.coast || p.ocean) {
centerContour[p.index] = 1;
queue.Enqueue(p);
}
}
while (queue.Count > 0) {
var p = queue.Dequeue();
foreach (var r in p.neighbors) {
var newLevel = centerContour.ContainsKey(p.index)?centerContour[p.index]:0;
while (newLevel < elevationThresholds.Length && (r.elevation > elevationThresholds[newLevel] && !r.water)) {
// NOTE: extend the contour line past bodies of water so that roads don't terminate inside lakes.
newLevel += 1;
}
if (centerContour.ContainsKey(r.index)){
if (newLevel < centerContour[r.index]){
centerContour[r.index] = newLevel;
queue.Enqueue(r);
}
}
}
}
// A corner's contour level is the MIN of its polygons
foreach (Center p in map.centers) {
foreach (var q in p.corners) {
int c1 = cornerContour.ContainsKey(q.index)?cornerContour[q.index]:999;
int c2 = centerContour.ContainsKey(p.index)?centerContour[p.index]:999;
cornerContour[q.index] = Mathf.Min(c1,c2);
}
}
// Roads go between polygons that have different contour levels
foreach (Center p in map.centers) {
foreach (var edge in p.borders) {
if (edge.v0 != null && edge.v1 !=null && cornerContour[edge.v0.index] != cornerContour[edge.v1.index]) {
road[edge.index] = Mathf.Min(cornerContour[edge.v0.index], cornerContour[edge.v1.index]);
if (!roadConnections.ContainsKey(p.index)) {
roadConnections[p.index] = new List<Edge>();
}
roadConnections[p.index].Add(edge);
}
}
}
}
示例8: CreateIDSpread
public bool CreateIDSpread(string projectPath, Dictionary<string, Dictionary<string, string>> idAllClass, ArrayList textFrameColumnClass)
{
_idAllClass = idAllClass;
_textFrameColumnClass = textFrameColumnClass;
int noOfTextFrames = textFrameColumnClass.Count;
const int pageCount = 3;
if (_idAllClass.ContainsKey("@page") || _idAllClass.ContainsKey("@page:first") || _idAllClass.ContainsKey("@page:left") || _idAllClass.ContainsKey("@page:right"))
{
_useMasterGrid = true;
}
for (int spread = 1; spread <= pageCount; spread++)
{
CreateaFile(projectPath, spread);
CreateSpread(spread);
CreateFlattenerPreference(); // Static code
CreatePage();
if (spread == 1)
{
CreateTextFrame(noOfTextFrames);
}
CloseFile(); // Static code
GetPagesPerSpread();
}
return true;
}
示例9: CreateEditor
/// <summary>
/// Creates a new editor for the supplied node type.
/// <param name="nodeType">The type of the node to be inspected.</param>
/// <returns>An editor for the supplied type.</returns>
/// </summary>
public static NodeEditor CreateEditor (Type nodeType) {
// Create type
if (s_CustomEditors == null) {
s_CustomEditors = new Dictionary<Type, Type>();
foreach (Type editorType in EditorTypeUtility.GetDerivedTypes(typeof(NodeEditor))) {
var customEditorAttr = AttributeUtility.GetAttribute<CustomNodeEditorAttribute>(editorType, true);
if (customEditorAttr != null) {
if (s_CustomEditors.ContainsKey(customEditorAttr.inspectedType))
s_CustomEditors[customEditorAttr.inspectedType] = editorType;
else
s_CustomEditors.Add(customEditorAttr.inspectedType, editorType);
// Add derived types?
if (customEditorAttr.editorForChildClasses) {
foreach (var childType in TypeUtility.GetDerivedTypes(customEditorAttr.inspectedType)) {
if (!s_CustomEditors.ContainsKey(childType))
s_CustomEditors.Add(childType, editorType);
}
}
}
}
}
// Try get custom nodeeditor attribute
Type customEditorType = null;
s_CustomEditors.TryGetValue(nodeType, out customEditorType);
if (customEditorType != null) {
var nodeEditor = Activator.CreateInstance(customEditorType) as NodeEditor;
if (nodeEditor != null)
return nodeEditor;
}
return new NodeEditor();
}
示例10: BatArg
public BatArg(Dictionary<string, string> keys)
{
Model = (BatModel)(int.Parse(keys["Model"]));
Hierarchy = (DestHierarchy)(int.Parse(keys["DestHierarchy"]));
PC = keys.ContainsKey("PC");
IOS = keys.ContainsKey("IOS");
AND = keys.ContainsKey("AND");
if (keys.TryGetValue("SrcFolder", out SrcFolder))
{
SrcFolder = Application.dataPath + SrcFolder;
SrcFolder.Replace("\\", "/");
}
if (keys.TryGetValue("SrcFolderName", out SrcFolderName)) SrcFolderName.Replace("\\", "/");
SearchLoop = keys.ContainsKey("SearchLoop");
if (keys.TryGetValue("SearchPrefix", out SearchPrefix)) SearchPrefix.Replace("\\", "/");
if (keys.TryGetValue("DestFolder", out DestFolderPath))
{
DestFolderPath = Application.dataPath + "/../.." + DestFolderPath;
DestFolderPath.Replace("\\", "/");
}
if (keys.TryGetValue("DestFolderName", out DestFolderName)) DestFolderName.Replace("\\", "/");
// Debug.Log(JsonWriter.Serialize(this));
}
示例11: CreateFromDictionary
public static GetUserDataResponse CreateFromDictionary(Dictionary<string, object> jsonMap)
{
try
{
if (jsonMap == null)
{
return null;
}
var request = new GetUserDataResponse();
if(jsonMap.ContainsKey("requestId"))
{
request.RequestId = (string) jsonMap["requestId"];
}
if(jsonMap.ContainsKey("amazonUserData"))
{
request.AmazonUserData = AmazonUserData.CreateFromDictionary(jsonMap["amazonUserData"] as Dictionary<string, object>);
}
if(jsonMap.ContainsKey("status"))
{
request.Status = (string) jsonMap["status"];
}
return request;
}
catch (System.ApplicationException ex)
{
throw new AmazonException("Error encountered while creating Object from dicionary", ex);
}
}
示例12: DeserializeCompany
/// <summary>
/// Deserializes Company from web api data.
///
/// IMPORTANT: Only values used for notification list will work at this implementation.
/// </summary>
/// <param name="companyDict"></param>
/// <returns></returns>
public Company DeserializeCompany(Dictionary<string, object> companyDict)
{
Company company = new Company();
System.Diagnostics.Debug.WriteLine("companyDict created");
company.id = companyDict["id"].ToString();
company.id = Hasher.Base64Encode(company.id);
if (companyDict.ContainsKey("name"))
{
company.name = companyDict["name"].ToString();
}
if (companyDict.ContainsKey("modified"))
{
company.name = companyDict["modified"].ToString();
}
if (companyDict.ContainsKey("logo"))
{
company.logo = companyDict["logo"].ToString();
}
return company;
}
示例13: CreateFromDictionary
public static Ad CreateFromDictionary(Dictionary<string, object> jsonMap)
{
try
{
if (jsonMap == null)
{
return null;
}
var request = new Ad();
if(jsonMap.ContainsKey("adType"))
{
request.AdType = (AdType) System.Enum.Parse(typeof(AdType), (string) jsonMap["adType"]);
}
if(jsonMap.ContainsKey("identifier"))
{
request.Identifier = (long) jsonMap["identifier"];
}
return request;
}
catch (System.ApplicationException ex)
{
throw new AmazonException("Error encountered while creating Object from dicionary", ex);
}
}
示例14: CsvLoadTripRoutes
public static void CsvLoadTripRoutes(string filename, bool lngFirst)
{
// load trip routes
Dictionary<string, LinkedList<Waypoint>> routes = new Dictionary<string, LinkedList<Waypoint>>();
using (CsvFileReader reader = new CsvFileReader(filename))
{
CsvRow row = new CsvRow();
while (reader.ReadRow(row, ','))
{
string routeID = row[0];
double distance = 0;
double lat = Convert.ToDouble(lngFirst ? row[2] : row[1]);
double lng = Convert.ToDouble(lngFirst ? row[1] : row[2]);
if (routes.ContainsKey(routeID))
distance = routes[routeID].First.Value.GetDistance(new Location(lat, lng, "null"));
Waypoint waypoint = new Waypoint(lat, lng, TimeSpan.Parse(row[3]), distance, row[4].Replace("\"", ""));
// Scenario #1
if (!routes.ContainsKey(routeID))
routes[routeID] = new LinkedList<Waypoint>();
routes[routeID].AddLast(waypoint);
}
}
foreach (LinkedList<Waypoint> w in routes.Values)
{
Route r = new Route(w.ToArray());
string key = Route.GetKey(r.start, r.end);
MapTools.routes.Add(key, r);
}
}
示例15: CreateFromDictionary
public static Placement CreateFromDictionary(Dictionary<string, object> jsonMap)
{
try
{
if (jsonMap == null)
{
return null;
}
var request = new Placement();
if(jsonMap.ContainsKey("dock"))
{
request.Dock = (Dock) System.Enum.Parse(typeof(Dock), (string) jsonMap["dock"]);
}
if(jsonMap.ContainsKey("horizontalAlign"))
{
request.HorizontalAlign = (HorizontalAlign) System.Enum.Parse(typeof(HorizontalAlign), (string) jsonMap["horizontalAlign"]);
}
if(jsonMap.ContainsKey("adFit"))
{
request.AdFit = (AdFit) System.Enum.Parse(typeof(AdFit), (string) jsonMap["adFit"]);
}
return request;
}
catch (System.ApplicationException ex)
{
throw new AmazonException("Error encountered while creating Object from dicionary", ex);
}
}