本文整理汇总了C#中System.Collections.Dictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Remove方法的具体用法?C# Dictionary.Remove怎么用?C# Dictionary.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HeavyChurn
public static void HeavyChurn(Simulator sim, int time)
{
sim.Complete();
Dictionary<Node, Node> volatile_nodes = new Dictionary<Node, Node>();
int fifteen_mins = (int) ((new TimeSpan(0, 15, 0)).Ticks / TimeSpan.TicksPerMillisecond);
int max = sim.StartingNetworkSize * 2;
Random rand = new Random();
DateTime end = DateTime.UtcNow.AddSeconds(time);
while(end > DateTime.UtcNow) {
SimpleTimer.RunSteps(fifteen_mins);
List<Node> to_remove = new List<Node>();
foreach(Node node in volatile_nodes.Keys) {
double prob = rand.NextDouble();
if(prob <= .7) {
continue;
}
// This is due to some bug that I can no longer remember
// sim.RemoveNode(node, prob > .9);
sim.RemoveNode(node, true);
to_remove.Add(node);
}
foreach(Node node in to_remove) {
volatile_nodes.Remove(node);
}
Console.WriteLine("Removed: {0} Nodes" , to_remove.Count);
while(volatile_nodes.Count < max) {
Node node = sim.AddNode();
volatile_nodes.Add(node, node);
}
}
}
示例2: Execute
public override string Execute(Dictionary<string, string> parameters)
{
string path = parameters["templatepath"];
if (string.IsNullOrEmpty(path)) return "";
string filename = parameters["templatefile"];
if (string.IsNullOrEmpty(filename)) return "";
try
{
string ModelProvider = parameters["dataprovider"];
string ModelConstructor = parameters["datasource"];
var ModelParameters = new Dictionary<string, string>(parameters);
ModelParameters.Remove("templatepath");
ModelParameters.Remove("templatefile");
ModelParameters.Remove("dataprovider");
ModelParameters.Remove("datasource");
var Model = DataSourceProvider.Instance(ModelProvider).Invoke(ModelConstructor, ModelParameters);
return TemplateProvider.FindProviderAndExecute(path, filename, Dump(Model));
}
catch (Exception ex)
{
return "Error : " + path + filename + " " + ex.Message;
}
}
示例3: Generate
/// <summary>
/// Calculates an intercept course for "imminent threat" pirates
/// </summary>
/// <param name="currentItem"></param>
/// <param name="dmID"></param>
public override void Generate(T_Item currentItem, String dmID)
{
if (currentItem.Parameters.ThreatType == T_ThreatType.Nonimminent)
return;
Dictionary<T_Move, T_Reveal> dict = GetActionsAsDictionary(currentItem.Action);
//This dictionary is a copy
Dictionary<T_Move, T_Reveal> newDict = new Dictionary<T_Move,T_Reveal>(dict);
//Find that pirate
T_Move move = null;
T_Reveal reveal = null;
foreach (T_Move key in dict.Keys)
{
if (dict[key] == null)
{
if (ddd.GetSeamateObject(key.ID).Owner == "Pirate DM")
{
move = key;
reveal = dict[key];
newDict.Remove(key);
break;
}
}
else
{
if (dict[key].Owner == "Pirate DM")
{
move = key;
reveal = dict[key];
newDict.Remove(key);
break;
}
}
}
if (move == null) return;
move = SetToInterceptCourse(move, reveal, newDict);
//Reset the pirate's move and reveal in dictionary.
newDict[move] = reveal;
//Translate dictionary back into action array.
currentItem.Action = GetActionsFromDictionary(newDict);
}
示例4: GetCentroid
public static TermVector GetCentroid(IEnumerable<TermVector> vectors)
{
Dictionary<string, long> sum = new Dictionary<string, long>();
int vectorCount = 0;
// Sum the lengths of dimensions
foreach (TermVector vector in vectors)
{
vectorCount++;
foreach (string term in vector.Terms)
{
long count = 0;
sum.TryGetValue(term, out count);
sum.Remove(term);
sum.Add(term, count + vector.GetDimensionLength(term));
}
}
// Divide the dimensions
Dictionary<string, int> centroid = new Dictionary<string, int>();
foreach (KeyValuePair<string, long> dimension in sum)
{
centroid.Add(dimension.Key, (int)(dimension.Value / vectorCount));
}
return new TermVector(centroid);
}
示例5: GumpDefTranslator
static GumpDefTranslator()
{
m_Translations = new Dictionary<int, Tuple<int, int>>();
StreamReader gumpDefFile = new StreamReader(FileManager.GetFile("gump.def"));
string line;
while ((line = gumpDefFile.ReadLine()) != null)
{
line = line.Trim();
if (line.Length <= 0)
continue;
if (line[0] == '#')
continue;
string[] defs = line.Replace('\t', ' ').Split(' ');
if (defs.Length != 3)
continue;
int inGump = int.Parse(defs[0]);
int outGump = int.Parse(defs[1].Replace("{", string.Empty).Replace("}", string.Empty));
int outHue = int.Parse(defs[2]);
if (m_Translations.ContainsKey(inGump))
m_Translations.Remove(inGump);
m_Translations.Add(inGump, new Tuple<int, int>(outGump, outHue));
}
gumpDefFile.Close();
}
示例6: PosTest2
public bool PosTest2()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest2: Verify method IDictionaryRemove when the specified key is not exist.");
try
{
IDictionary dictionary = new Dictionary<string, string>();
dictionary.Remove("txt");
if (dictionary.Contains("txt") == true)
{
TestLibrary.TestFramework.LogError("002.1", "Method IDictionary.GetEnumerator Err .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例7: GetDataByGroupYear
private IDictionary<string, IList<Brief>> GetDataByGroupYear()
{
IDictionary<string, IList<Brief>> result = new Dictionary<string, IList<Brief>>();
SetConditions(string.Empty);
m_Conditions.Add("Status", "1");
IList<Brief> dataList = m_FTISService.GetBriefList(m_Conditions);
if (dataList != null && dataList.Count() > 0)
{
foreach (Brief data in dataList)
{
string key = data.AYear.Trim();
IList<Brief> groupDataList = new List<Brief>();
if (result.ContainsKey(key))
{
groupDataList = result[key];
result.Remove(key);
}
groupDataList.Add(data);
result.Add(key, groupDataList);
}
}
return result;
}
示例8: Dictionary
public static Dictionary<string, object> Dictionary(string[] keys, object[] values)
{
var table = new Dictionary<string, object>();
values = (object[]) values[0];
for (int i = 0; i < keys.Length; i++)
{
string name = keys[i].ToLowerInvariant();
object entry = i < values.Length ? values[i] : null;
if (entry == null)
{
if (table.ContainsKey(name))
table.Remove(name);
}
else
{
if (table.ContainsKey(name))
table[name] = entry;
else
table.Add(name, entry);
}
}
return table;
}
示例9: findMovableTiles
public static List<GameObject> findMovableTiles(GameObject tile, int maxDist, Dictionary<terrainType,int> moveDict)
{
List<GameObject> openList = new List<GameObject>();
List<GameObject> closedList = new List<GameObject>();
List<GameObject> result = new List<GameObject>();
Dictionary <GameObject, int> gScore = new Dictionary<GameObject, int>();
GameObject currentNode;
openList.Add(tile);
result.Add(tile);
gScore.Add (tile,0);
while(openList.Count > 0){
currentNode = openList[0];
foreach(GameObject hex in currentNode.GetComponent<MapHex>().neighborList){
int tempG = (gScore[currentNode]+moveDict[hex.GetComponent<MapHex>().getTerrain()]);
if(!openList.Contains(hex)&&!closedList.Contains(hex)&&tempG<=maxDist){
gScore.Add (hex,tempG);
openList.Add (hex);
}
else if(tempG<gScore[hex]&&gScore.ContainsKey(hex)){
gScore.Remove (hex);
gScore.Add (hex,tempG);
}
}
closedList.Add(currentNode);
openList.Remove(currentNode);
if(gScore[currentNode]<=maxDist)result.Add(currentNode);
}
return result;
}
示例10: Update
void Update()
{
var remove_candidates = new Dictionary<ulong, Text>(name_dict_); // 削除候補辞書
var player_gos = GameObject.FindGameObjectsWithTag("Player"); // タグPlayerでリストアップ
if (player_gos != null) {
foreach (var player_go in player_gos) {
var player = player_go.GetComponent<Player>();
if (player.sharedNod == null)
continue;
ulong id = player.sharedNod.getGlobalId(); // IDを取得
Text text;
if (name_dict_.ContainsKey(id)) { // すでに存在していた
text = name_dict_[id]; // 取得
remove_candidates.Remove(id); // 削除候補から消す
} else { // 存在していなかった
var go = Instantiate(namePrefab_) as GameObject; // 生成
text = go.GetComponent<Text>(); // 取得
go.transform.SetParent(canvas_); // 親を指定
name_dict_[id] = text; // 辞書に登録
}
text.text = player.name_; // テキストに名前を入れる
var screenPos = Camera.main.WorldToScreenPoint(player_go.transform.position); // 2D位置を取得
text.transform.position = screenPos; // 設定
}
}
// 消えたものを削除
foreach (KeyValuePair<ulong, Text> pair in remove_candidates) {
name_dict_.Remove(pair.Key); // 辞書から削除
Destroy(pair.Value.gameObject); // オブジェクト破棄
}
}
示例11: FindFirstChar
/* Find first character which is not repetitve in string
* if string has length n, it may need n*n time O(n).
* Let's find a better algorithm
* First, make Hash table that saves the number of character appears in string
* for each char
* if, not saved value for the char, save 1
* else, value++;
* Second, lookup character
* for each char
* if, the number of appears = 1, return char
* else, 1 not exists, return null
*/
public static char FindFirstChar(string str)
{
Dictionary<char,int> table = new Dictionary<char, int>();
int length = str.Length;
char c;
int i;
for (i = 0; i< length; i++)
{
c = str[i];
if (table.ContainsKey (c)) {
int temp = table [c];
table.Remove (c);
table.Add (c, temp+1);
} else {
table.Add (c, 1);
}
}
for ( i = 0; i<length; i++)
{
c = str[i];
if (table [c] == 1) {
return c;
}
}
char Null = '\0';
return Null;
}
示例12: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: The key to be remove is a custom class");
try
{
IDictionary iDictionary = new Dictionary<object,object>();
MyClass mc = new MyClass();
int value = TestLibrary.Generator.GetInt32(-55);
iDictionary.Add(mc, value);
iDictionary.Remove(mc);
if (iDictionary.Contains(mc))
{
TestLibrary.TestFramework.LogError("003", "The result is not the value as expected ");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
示例13: WriteRuleRequestRecordLog
public void WriteRuleRequestRecordLog(Dictionary<string, string> FailedTestResult)
{
System.IO.StreamWriter logStream = this.CreateTestResultFile(this.Site.Properties["Conformance_Response_Data_Path"], ".log");
if (logStream == null)
return;
try
{
IDictionaryEnumerator ruleRequestRecord = ((ConformanceDataService)dataService).RequestRecords;
logStream.WriteLine("------conformance test result ( failed count {0} )------", FailedTestResult.Count);
while (ruleRequestRecord.MoveNext())
{
string rulename = (string)ruleRequestRecord.Key;
if (FailedTestResult.ContainsKey(rulename))
{
string result = string.Empty;
List<string> reqeustRecords = (List<string>)ruleRequestRecord.Value;
result += "\t" + reqeustRecords.Count.ToString();
foreach (string record in reqeustRecords)
{
result += "\t" + record;
}
logStream.WriteLine(string.Format("{0}\t{1}{2}", rulename, FailedTestResult[rulename], result));
FailedTestResult.Remove(rulename);
}
else
{
List<string> reqeustRecords = (List<string>)ruleRequestRecord.Value;
logStream.WriteLine(string.Format("{0}\tsuccess\t{1}", rulename, reqeustRecords.Count));
}
}
if (FailedTestResult.Count != 0)
{
logStream.WriteLine("some rule's request not in ConformanceDataService.ruleRequestRecord");
}
foreach (var ruleResult in FailedTestResult)
{
string rulename = ruleResult.Key;
logStream.WriteLine(rulename + "\t" + ruleResult.Value);
}
logStream.WriteLine();
}
catch (Exception ex)
{
logStream.WriteLine("Exception occur when write log");
logStream.WriteLine(ex);
}
finally
{
logStream.Close();
}
}
示例14: Serveur
/// <summary>
/// Se charge d'initialiser la connection
/// </summary>
public Serveur()
{
chatServer = new TcpListener(9595);
ServerUp = true;
ClientList = new Dictionary<int, TcpClient>();
chatServer.Start();
Console.WriteLine("Server Up");
while (ServerUp)
{
TcpClient chatClient = null;
chatClient = chatServer.AcceptTcpClient();
Console.WriteLine("You are now connected");
StreamReader reader = new StreamReader(chatClient.GetStream());
int id = Convert.ToInt32(reader.ReadLine());
Console.WriteLine("Id obtained: " + id);
if (ClientList.ContainsKey(id))
{
ClientList[id].Close();
ClientList.Remove(id);
}
ClientList.Add(id, chatClient);
ClientManager manager = new ClientManager(this, chatClient, id);
}
}
示例15: Test3
public void Test3(int arg) {
Dictionary<string, int> dictionary1 = new Dictionary<string, int>("aaa", 123, "xyz", true);
string key = "blah";
int c = dictionary1.Count;
int c2 = GetData2().Count;
bool b = dictionary1.ContainsKey("aaa");
dictionary1.Remove("aaa");
dictionary1.Remove("Proxy-Connection");
dictionary1.Remove(key);
dictionary1.Clear();
string[] keys = dictionary1.Keys;
}