本文整理汇总了C#中Dictionary.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ToList方法的具体用法?C# Dictionary.ToList怎么用?C# Dictionary.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1_Load_1
private void Form1_Load_1(object sender, EventArgs e)
{
var source = new Dictionary<string, uint>();
source.Add("F1", 0x70);
source.Add("F2", 0x71);
source.Add("F3", 0x72);
source.Add("F4", 0x73);
source.Add("F5", 0x74);
source.Add("F6", 0x75);
source.Add("F7", 0x76);
source.Add("F8", 0x77);
source.Add("F9", 0x78);
source.Add("F10", 0x79);
source.Add("F11", 0x80);
source.Add("F12", 0x81);
this.mana_hotkey.DataSource = source.ToList();
this.mana_hotkey.DisplayMember = "Key";
this.mana_hotkey.ValueMember = "Value";
this.light_heal_hotkey.DataSource = source.ToList();
this.light_heal_hotkey.DisplayMember = "Key";
this.light_heal_hotkey.ValueMember = "Value";
this.intense_heal_hotkey.DataSource = source.ToList();
this.intense_heal_hotkey.DisplayMember = "Key";
this.intense_heal_hotkey.ValueMember = "Value";
}
示例2: AveragedPerceptron
private Dictionary<string, double> weightVector; //Implemented as a map since it is simpler
#endregion Fields
#region Constructors
public AveragedPerceptron(string category, List<Dictionary<string, int>> docsOfCategory, List<Dictionary<string, int>> docsNotOfCat,
double learningRate, int iterations, double bias, ISet<string> vocabulary)
{
if (learningRate <= 0 || learningRate >= 1)
throw new ArgumentOutOfRangeException("0 < learningRate < 1 must be satisfied");
this.category = category;
this.learningRate = learningRate;
this.bias = bias;
int trainingSize = docsNotOfCat.Count + docsOfCategory.Count;
//Initialize the weightvectors
weightVector = new Dictionary<string, double>();
foreach (var word in vocabulary)
{
weightVector.Add(word, 0);
}
averageWeightVector = new Dictionary<string, double>(weightVector);
for (int i = 0; i < iterations; i++)
{
//Learn from training data
foreach (var doc in docsOfCategory)
{
this.Learn(true, doc, i, iterations, trainingSize);
}
foreach (var doc in docsNotOfCat)
{
this.Learn(false, doc, i, iterations, trainingSize);
}
}
List<KeyValuePair<string, double>> weightList = weightVector.ToList();
weightList.Sort((firstPair, nextPair) => { return firstPair.Value.CompareTo(nextPair.Value); });
}
示例3: ShowBeautyNumber
static void ShowBeautyNumber(string line)
{
line = line.ToLower();
string pattern = "[^a-z]";
string replacement = "";
Regex rgx = new Regex(pattern);
string resultStr = rgx.Replace(line, replacement);
Dictionary<char, int> myMap = new Dictionary<char, int>();
foreach(char ch in resultStr){
if(!myMap.ContainsKey(ch)){
myMap.Add(ch,0);
}
myMap[ch] += 1;
}
List<KeyValuePair<char, int>> myList = myMap.ToList();
myList.Sort((firstPair,nextPair) =>{
return -firstPair.Value.CompareTo(nextPair.Value);
});
int beauty = 26;
int result = 0;
foreach(KeyValuePair<char, int> itm in myList){
result += itm.Value*beauty;
beauty--;
}
Console.WriteLine(result);
}
示例4: Main
static void Main(string[] args)
{
Console.WriteLine("String :");
string text = Console.ReadLine();
List<string> checkedWords = new List<string>();
string[] words = text.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, int> count = new Dictionary<string, int>();
for (int i = 0; i < words.Length; i++)
{
string word = words[i];
if (!checkedWords.Contains(word))
{
count.Add(word, words.Count(x => x == word));
checkedWords.Add(word);
}
}
List<KeyValuePair<string, int>> sorted = count.ToList();
sorted.Sort((x, y) => { return y.Value.CompareTo(x.Value); });
foreach (var item in sorted)
{
Console.WriteLine("{0} - {1}", item.Key, item.Value);
}
}
示例5: Main
static void Main(string[] args)
{
Dictionary<char, int> symbols = new Dictionary<char, int>();
string text = Console.ReadLine();
for (int i = 0; i < text.Length; i++)
{
char currentChar = Convert.ToChar(text[i]);
if (!symbols.ContainsKey(text[i]))
{
symbols[currentChar] = 0;
}
symbols[currentChar]++;
}
var orderedSymbols = symbols.ToList();
orderedSymbols.Sort(delegate(KeyValue<char, int> c1, KeyValue<char, int> c2) { return c1.Key.CompareTo(c2.Key); });
foreach (var symbol in orderedSymbols)
{
Console.WriteLine(symbol + " time/s");
}
}
示例6: GetProductList
private IList<KeyValuePair<string, string>> GetProductList()
{
Dictionary<string, string> dicProductList = new Dictionary<string, string>();
//橡膠
dicProductList.Add("JRU-橡膠", "81");
//黃金
dicProductList.Add("JAU-黃金", "11");
//小黃金
dicProductList.Add("JAM-小黃金", "16");
//白銀
dicProductList.Add("JSV-白銀", "12");
//白金
dicProductList.Add("JPL-//白金", "13");
//小白金
dicProductList.Add("JPM-小白金", "17");
//鈀金
dicProductList.Add("JPA-鈀金", "14");
//汽油
dicProductList.Add("JGL-汽油", "31");
//燃油
dicProductList.Add("JKE-燃油", "32");
//原油
dicProductList.Add("JCO-原油", "33");
return dicProductList.ToList();
}
示例7: SetExtractOutput
public static void SetExtractOutput(DependencyObject dependencyObject, Dictionary<string, string> list)
{
MainWindow mainWindow = MainContext.GetMainWindow(dependencyObject);
LayoutAnchorable documentPane = mainWindow.MainDockingManager.Layout.Descendents()
.OfType<LayoutAnchorable>()
.FirstOrDefault(c => c.ContentId == "OutputContent");
if (documentPane != null)
{
if (documentPane.IsAutoHidden)
{
documentPane.ToggleAutoHide();
}
var content = documentPane.Content as OutputPageUserControl;
if (content != null)
{
LayoutDocumentPane panes =
content.OutputDockingManager.Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
for (; panes.ChildrenCount > 0; )
{
LayoutContent pane = panes.Children[0];
pane.Close();
}
foreach (var pair in list.ToList())
{
var outputContentUserControl = new OutputContentUserControl();
outputContentUserControl.ContentTextEditor.Text = pair.Value;
UtilityManager.CreateTab(content.OutputDockingManager, outputContentUserControl, pair.Key);
}
}
}
}
示例8: GetPoiInformation
public static JsonArray GetPoiInformation(Location userLocation, int numberOfPlaces)
{
if (userLocation == null)
return null;
var pois = new List<JsonObject> ();
for (int i = 0; i < numberOfPlaces; i++)
{
var loc = GetRandomLatLonNearby (userLocation.Latitude, userLocation.Longitude);
var p = new Dictionary<string, JsonValue>(){
{ "id", i.ToString() },
{ "name", "POI#" + i.ToString() },
{ "description", "This is the description of POI#" + i.ToString() },
{ "latitude", loc[0] },
{ "longitude", loc[1] },
{ "altitude", 100f }
};
pois.Add (new JsonObject (p.ToList()));
}
var vals = from p in pois select (JsonValue)p;
return new JsonArray (vals);
}
示例9: Main
static void Main(string[] args)
{
var matches = GetWords();
Dictionary<string, int> wordOccurance = new Dictionary<string, int>();
foreach (var word in matches)
{
string strWord = word.ToString();
if (wordOccurance.ContainsKey(strWord))
{
wordOccurance[strWord] += 1;
}
else
{
wordOccurance.Add(strWord, 1);
}
}
List<KeyValuePair<string, int>> wordPairs = wordOccurance.ToList();
wordPairs.Sort((x, y) => x.Value.CompareTo(y.Value));
foreach (var entry in wordPairs)
{
Console.WriteLine("{0}: {1}", entry.Key, entry.Value);
}
}
示例10: RankedResults
public List<KeyValuePair<string, double>> RankedResults()
{
List<Document> documents = new List<Document>();
HashSet<string> dataSet = new HashSet<string>();
foreach (var result in results)
{
Document d = new Document(result);
documents.Add(d);
foreach (var term in d.tokens()){
dataSet.Add(term);
}
}
//Build Document Vectors
Dictionary<string, Vector> documentVectors = new Dictionary<string, Vector>();
foreach (var document in documents)
{
documentVectors.Add(document.ToString(), new Vector(dataSet, document));
}
//Build Query Vector
Query query = new Query(queryString);
Vector queryVector = new Vector(dataSet, query);
Dictionary<string, double> relevance = new Dictionary<string, double>();
foreach (var documentVector in documentVectors)
{
relevance.Add(documentVector.Key, Vector.GetSimilarityScore(queryVector, documentVector.Value));
}
//Sort result by most relevant
List<KeyValuePair<string, double>> myList = relevance.ToList();
return myList;
}
示例11: Main
public static void Main()
{
string text = @"C# is not C++, not PHP and not Delphi! Write a program that extracts from a given text all palindromes, e.g. ""ABBA"", ""lamal"", ""exe"".";
//Console.WriteLine("Please enter your text:");
//string text = Console.ReadLine();
string regex = @"[A-Z]+";
Dictionary<string, int> wordOccurrences = new Dictionary<string, int>();
MatchCollection matches = Regex.Matches(text, regex, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match match in matches)
{
if (wordOccurrences.ContainsKey(match.Value))
{
wordOccurrences[match.Value]++;
}
else
{
wordOccurrences.Add(match.Value, 1);
}
}
// var sortedDictionary = (from entry in wordOccurrences orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
List<KeyValuePair<string, int>> sortedDictionary = wordOccurrences.ToList();
sortedDictionary.Sort((x, y) => x.Key.CompareTo(y.Key));
foreach (KeyValuePair<string, int> wordEntry in sortedDictionary)
{
Console.WriteLine("{0}: {1}", wordEntry.Key, wordEntry.Value);
}
}
示例12: ProcessRequest
/// <summary>
/// Json Çıktısı Olarak AppData İçindeki İlleri Servisten Yayınlıyoruz
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
Dictionary<int,string> iller = new Dictionary<int, string>();
using (StreamReader stramreader = new StreamReader(context.Server.MapPath("App_Data\\veri.txt")))
{
while (stramreader.Peek()>=0)
{
try
{
string[] satir = stramreader.ReadLine().ToString().Split(' ');
iller.Add(int.Parse(satir[0].Trim()), satir[1]);
}
catch (Exception)
{
}
}
}
context.Response.Write(JsonConvert.SerializeObject(iller.ToList()));
}
示例13: IronPythonComposablePart
public IronPythonComposablePart(IronPythonTypeWrapper typeWrapper, IEnumerable<Type> exports, IEnumerable<KeyValuePair<string, IronPythonImportDefinition>> imports)
{
_typeWrapper = typeWrapper;
_instance = typeWrapper.Activator();
_exports = new List<ExportDefinition>(exports.Count());
_imports = new Dictionary<string, ImportDefinition>(imports.Count());
foreach (var export in exports)
{
var metadata = new Dictionary<string, object>()
{
{"ExportTypeIdentity", AttributedModelServices.GetTypeIdentity(export)}
};
var contractName = AttributedModelServices.GetContractName(export);
_exports.Add(new ExportDefinition(contractName, metadata));
}
foreach (var import in imports)
{
var contractName = AttributedModelServices.GetContractName(import.Value.Type);
var metadata = new Dictionary<string, Type>();
_imports[import.Key] = new IronPythonContractBasedImportDefinition(
import.Key,
contractName,
AttributedModelServices.GetTypeIdentity(import.Value.Type),
metadata.ToList(),
import.Value.Cardinality, import.Value.IsRecomposable, import.Value.IsPrerequisite,
CreationPolicy.Any);
}
}
示例14: onBonusesLoaded
void onBonusesLoaded(Dictionary<long, string> difficultyIds)
{
List<KeyValuePair<long, string>> list = difficultyIds.ToList();
list.Sort((first, second) => first.Key.CompareTo(second.Key));
foreach (KeyValuePair<long, string> pair in list)
addButton(pair);
}
示例15: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
tableColumns = (Dictionary<string, List<DB.Column>>)Session["tableColumns"];
if (null == tableColumns) return;
var dbo = new DB.DBCalls();
tableColumns.ToList().ForEach(table =>
{
var query = "alter table [" + client + "].[" + table.Key + "] add ";
table.Value.ForEach(column =>
{
query += "[" + column.ColumnName + "] " + column.DataType.ToString();
if ((column.DataType == System.Data.SqlDbType.VarChar) || (column.DataType == System.Data.SqlDbType.NVarChar) || (column.DataType == System.Data.SqlDbType.Char) || (column.DataType == System.Data.SqlDbType.Char) || (column.DataType == System.Data.SqlDbType.NChar))
{
query += "(" + column.Length.ToString() + ")";
}
query += (column.IsNullable) ? " null " : " not null ";
query += (string.IsNullOrEmpty(column.DefaultValue)) ? "" : " default '" + column.DefaultValue + "'";
query += ", ";
});
query = query.Remove(query.LastIndexOf(","), 2);
try
{
dbo.ExecuteString(query);
}
catch (System.Data.SqlClient.SqlException sqlE)
{
}
});
}