本文整理汇总了C#中System.Collections.Dictionary.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Count方法的具体用法?C# Dictionary.Count怎么用?C# Dictionary.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: returnKeyMap2
public XmlRpcStruct[] returnKeyMap2()
{
Console.WriteLine("Hashmap request");
Dictionary<int, String> machines = new Dictionary<int, String>();
machines.Add(1, "test1");
machines.Add(3, "test3");
Console.WriteLine("Machines number now " + machines.Count());
XmlRpcStruct[] test = ConvertDictionaryToStruct(machines);
return test;
}
示例2: returnKeyMap
public XmlRpcStruct[] returnKeyMap(String ipAddress, int priority)
{
Console.WriteLine("Hashmap request from ip " + ipAddress + " with priority " + priority);
Dictionary<int, String> machines = new Dictionary<int, String>();
machines.Add(1, "test1");
machines.Add(3, "test3");
Console.WriteLine("Machines number now " + machines.Count());
XmlRpcStruct[] test = ConvertDictionaryToStruct(machines);
return test;
}
示例3: Multi_Reg_Check
public bool Multi_Reg_Check()
{
Dictionary<string, string> depDic = new Dictionary<string, string>();
if (ViewState["dict"] != null)
{ depDic = (Dictionary<string, string>)ViewState["dict"]; }
if (depDic.Count > 0 && depDic.Values.Contains("d") && depDic.Count(D=>D.Value.Contains("i")) >= 2)
{
return true;
}
return false;
}
示例4: ConvertDictionaryToStruct
private XmlRpcStruct[] ConvertDictionaryToStruct(Dictionary<int, string> dict)
{
XmlRpcStruct[] convertionResult = new XmlRpcStruct[dict.Count()];
for (int i = 0; i < dict.Count; i++)
{
convertionResult[i] = new XmlRpcStruct();
convertionResult[i].Add("NetworkPriority", dict.Keys.ElementAt(i));
convertionResult[i].Add("IpAddress", dict.Values.ElementAt(i));
}
return convertionResult;
}
示例5: JointState
static JointState()
{
NamesToJoints = new Dictionary<string, int>() {
{"neck", 0},
{"head", 1},
{"right-shoulder", 2},
{"left-shoulder", 6},
{"right-elbow", 3},
{"left-elbow", 7},
{"right-wrist", 4},
{"right-pelvis", 18},
{"left-pelvis", 19},
{"left-wrist", 8},
{"right-palm", 5},
{"right-hip", 10},
{"left-hip", 14},
{"left-palm", 9},
{"right-knee", 11},
{"left-knee", 15},
{"right-ankle", 12},
{"right-foot", 13},
{"left-ankle", 16},
{"left-foot", 17}
};
JointParents = new List<int>() { -1, // Neck
0, // Head
0, 2, 3, 4,
0, 6, 7, 8,
18, 10, 11, 12,
19, 14, 15, 16,
0, 0
};
// Sanity check
foreach ( var nj in NamesToJoints ) {
var c = NamesToJoints.Count(x => (x.Value == nj.Value));
if ( c > 1 ) throw new Exception("Duplicate joints in relative joint name list!");
}
foreach ( var jp in JointParents ) {
// TODO: check that there are no cycles here
}
}
示例6: id3
public id3( id3 _padre, List<string[]> _baseConocimiento,
Dictionary<string, Tuple<int, Dictionary<string, int>>>[] _dominio,string[] _att_name, string _value, int _colRes)
{
att_elegido = "";
value_att = _value;
resultado = "";
default_value = _padre.default_value;
colRes = _colRes;
att_name = _att_name;
baseConocimiento = _baseConocimiento;
hijos = new List<id3>();
nAtt = _padre.nAtt - 1;
dominio = _dominio;
for(int i = 0; i < dominio.Count(); i++)
{
//foreach(var keyAtt in dominio[i].Keys)
for(int index2 = 0; index2 < dominio[i].Keys.Count(); index2++)
{
var _name = dominio[i].Keys.ElementAt(index2);
var keyAtt = dominio[i][_name].Item2.Keys;
//foreach(var key in dominio[i][keyAtt].Item2.Keys)
for (int j = 0; j < keyAtt.Count(); j++)
{
var _qwe = keyAtt.ElementAt(j);
dominio[i][_name].Item2[_qwe] = 0;
}
dominio[i][_name] = Tuple.Create(0, dominio[i][_name].Item2);
}
}
var k = 0;
foreach(var ej in baseConocimiento)
{
dominio[k][ej[k]].Item2[ej[colRes]]++;
dominio[k][ej[k]] = Tuple.Create(dominio[k][ej[k]].Item1 + 1, dominio[k][ej[k]].Item2);
k++;
}
}
示例7: Main
static void Main(string[] args)
{
foreach (String name in Directory.GetFiles(_picturesDirectory, "*.jpg"))
_knownNames.Add(name);
Dictionary<DateTime, string> nameDic = new Dictionary<DateTime, string>();
foreach (String name in _knownNames)
nameDic.Add(Directory.GetCreationTime(name), name);
var lastime = nameDic.Count() > 0 ? nameDic.Last().Key : DateTime.Now;
StreamReader r = new StreamReader(_picturesDirectory + "\\list.txt");
String line;
while ((line = r.ReadLine()) != null)
{
nameDic.Add(lastime, line);
lastime = lastime.AddSeconds(1);
}
foreach (var item in nameDic.OrderByDescending(x=>x.Key))
FindFollowers(
String.Format("https://api.twitter.com/1/followers/[email protected]{0}", Path.GetFileNameWithoutExtension(item.Value)));
}
示例8: UpdateDbConditionNameList
private void UpdateDbConditionNameList(String strConditionNameList)
{
FileLog.PrintF("UpdateDbConditionNameList strConditionNameList=>" + strConditionNameList);
/*strConditionNameList==> 비고 조건명 리스트를 구분(“;”)하여 받아온다.Ex) 인덱스1 ^ 조건명1; 인덱스2 ^ 조건명2; 인덱스3 ^ 조건명3;…*/
String lastChar = strConditionNameList.Substring(strConditionNameList.Count() - 1, 1);
if (lastChar.Equals(";"))//마지막글자가 ; 이거이면 빈 배열공간이 하나 더생기므로 마지막 ; 이것이면 삭제
{
strConditionNameList = strConditionNameList.Substring(0, strConditionNameList.Count() - 1);
}
String[] tmp=strConditionNameList.Split(';');
Dictionary<int, String> conditionNameList = new Dictionary<int, String>();
for(int i = 0; i < tmp.Count(); i++)
{
String[] strTmp = tmp[i].Split('^');
FileLog.PrintF("UpdateDbConditionNameList nIndex=>" + strTmp[0]);
FileLog.PrintF("UpdateDbConditionNameList conditionName=>" + strTmp[1]);
int nIndex = int.Parse(strTmp[0].Trim());
String conditionName = strTmp[1];
conditionNameList.Add(nIndex, conditionName);
}
try
{
using (MySqlConnection conn = new MySqlConnection(Config.GetDbConnStr()))
{
String sql1 = "DELETE FROM condition_names;";
conn.Open();
MySqlTransaction tr = conn.BeginTransaction();
String dayTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
try
{
MySqlCommand cmd = new MySqlCommand(sql1, conn, tr);
cmd.ExecuteNonQuery();
string sql2 = @"INSERT INTO condition_names (
condition_name
,nIndex
,created_at
,updated_at
)
VALUES";
String sql2_1 = @"
(
@조건이름{0}
,@인덱스{0}
,@등록날짜{0}
,@업데이트날짜{0}
),";
StringBuilder queryBuilder = new StringBuilder(sql2);
for (int i = 0; i < conditionNameList.Count(); i++)
{
queryBuilder.AppendFormat(sql2_1, i);
//once we're done looping we remove the last ',' and replace it with a ';'
if (i == conditionNameList.Count() - 1)
{
queryBuilder.Replace(',', ';', queryBuilder.Length - 1, 1);
}
}
String sql2_2 = queryBuilder.ToString();
FileLog.PrintF("UpdateDbConditionNameList sql2_2:" + sql2_2.ToString());
cmd.CommandText = sql2_2;
int j = 0;
foreach (var h in conditionNameList)
{
cmd.Parameters.AddWithValue("@조건이름" + j, h.Value); //[0]
cmd.Parameters.AddWithValue("@인덱스" + j, h.Key); //[1]
cmd.Parameters.AddWithValue("@등록날짜" + j, dayTime); //[2]
cmd.Parameters.AddWithValue("@업데이트날짜" + j, dayTime); //[3]
j++;
}
cmd.ExecuteNonQuery();
tr.Commit();
}
catch (MySqlException ex2)
{
try
{
tr.Rollback();
}
catch (MySqlException ex1)
{
FileLog.PrintF("UpdateDbConditionNameList1 Error:" + ex1.ToString());
}
FileLog.PrintF("UpdateDbConditionNameList2 Error:" + ex2.ToString());
}
}
}
catch (MySqlException ex3)
{
FileLog.PrintF("UpdateDbConditionNameList3 Error:" + ex3.ToString());
}
}
示例9: UpdateNamespace
public NamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, NamespaceState state, bool critical, Dictionary<string, string> tags)
{
var parameter = new NamespaceCreateOrUpdateParameters()
{
Location = location,
Properties = new NamespaceProperties()
{
NamespaceType = NamespaceType.NotificationHub,
Status = ((state == NamespaceState.Disabled) ? state : NamespaceState.Active).ToString(),
Enabled = (state == NamespaceState.Disabled ) ? false:true
}
};
if (critical)
{
parameter.Properties.Critical = critical;
}
if (tags != null && tags.Count() > 0)
{
parameter.Tags = new Dictionary<string, string>(tags);
}
var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter);
return new NamespaceAttributes(resourceGroupName, response.Value);
}
示例10: Training2
public void Training2(Dictionary<double[], int> Examples)
{
double Error= 5;
int Iteraciones = 0;
StreamWriter stream = System.IO.File.CreateText("Log_Training_" + Neuronas_Ocultas + "_" + Max_Iteracion + ".txt");
while (Error > 0.3 && Iteraciones < Max_Iteracion)
{
Error = 0;
Iteraciones++;
foreach (var E in Examples)
{
// Calcular la salida de la red (a)
List<Nodo> Aux = NN.GetLayer(0); //Layer de Entrada
for (int j = 1; j < Aux.Count; j++)
Aux[j].a = E.Key[j - 1];
Aux[0].a = 1;
for (int j = 1; j < NN.N_Layar(); j++)
foreach (Nodo i in NN.GetLayer(j))
{
double Sum = 0;
foreach (Arco A in NN.GetArcs(i))
Sum += A.W * A.Ini.a;
i.In = Sum;
i.a = g(i.In);
}
//Para cada unidad de Salida k
foreach (Nodo k in NN.GetLayer(NN.N_Layar() - 1))
{
Error += (E.Value - k.a) * (E.Value - k.a);
k.delta = k.a * (1 - k.a) * (E.Value - k.a);
}
// Por cada Unidad Oculta h
for (int l = 1 ; l < NN.N_Layar() - 1; l++)
foreach (Nodo h in NN.GetLayer(l))
{
double Sum = 0;
foreach (Arco A in NN.GetArcsInv(h))
Sum += A.W * A.Fin.delta;
h.delta = h.a * ( 1 - h.a ) * Sum;
}
//Actualizar cada peso de la red (W)
for (int j = 1; j < NN.N_Layar(); j++)
foreach (Nodo i in NN.GetLayer(j))
foreach (Arco A in NN.GetArcs(i))
A.W += Ta * A.Fin.delta * A.Ini.a;
}
Error /= Examples.Count();
Error = Math.Sqrt(Error);
stream.WriteLine(Error);
}
stream.Close();
}
示例11: Training
public void Training(Dictionary<double[], int> Examples)
{
double Error;
int Iteraciones = 0;
StreamWriter stream = System.IO.File.CreateText("Log_Training_"+Neuronas_Ocultas+"_"+Max_Iteracion+".txt");
do
{
Iteraciones++;
Error = 0;
foreach (var E in Examples)
{
// ForwardPropagate
List<Nodo> Aux = NN.GetLayer(0); //Layer de Entrada
for (int j = 1; j < Aux.Count; j++)
Aux[j].a = E.Key[j - 1];
Aux[0].a = 1;
for (int j = 1; j < NN.N_Layar(); j++)
foreach (Nodo i in NN.GetLayer(j))
{
double Sum = 0;
foreach (Arco A in NN.GetArcs(i))
Sum += A.W * A.Ini.a;
i.In = Sum;
i.a = g(i.In);
}
foreach (Nodo i in NN.GetLayer(NN.N_Layar() - 1))
{
Error += (E.Value - i.a) * (E.Value - i.a);
i.delta = dg(i.In) * (E.Value - i.a);
}
//BackPropagate
for (int l = NN.N_Layar() - 2; l >= 0; l--)
foreach (Nodo j in NN.GetLayer(l))
{
double Sum = 0;
foreach (Arco A in NN.GetArcsInv(j))
Sum += A.W * A.Fin.delta;
j.delta = dg(j.In) * Sum;
foreach (Arco A in NN.GetArcsInv(j))
A.W += Ta * j.a * A.Fin.delta;
}
}
Error /= Examples.Count();
Error = Math.Sqrt(Error);
stream.WriteLine(Error);
} while (Error > 0.84 && Iteraciones < Max_Iteracion);
stream.Close();
}
示例12: checkSingleRowOperationInverseQuestion
public String checkSingleRowOperationInverseQuestion(Dictionary<int, float[,]> matrixMap)
{
String feedback = "";
for (int i = 0; i < matrixMap.Count()-1; i++)
{
float[,] matrix1 = null;
matrixMap.TryGetValue(i, out matrix1);
float[,] matrix2 = null;
matrixMap.TryGetValue(i + 1, out matrix2);
if (checkMatrixEquality(matrix1, matrix2))
{
feedback += "<div>No row operation between matrix " + i + " and matrix " + (i + 1) + ".<div>";
}
else if (!checkAddMultipleOfRow(matrix1, matrix2) && !checkTimesScalar(matrix1, matrix2)
&& !checkRowSwap(matrix1, matrix2))
{
feedback += "<div>Mistake between matrix " + i + " and matrix " + (i + 1) + ".<div>";
}
}
return feedback.Equals("") ? null : feedback;
}
示例13: UploadAttach_ysd
public ActionResult UploadAttach_ysd()
{
try
{
供应商 model = 用户管理.查找用户<供应商>(currentUser.Id);
Dictionary<string, List<string>> url = new Dictionary<string, List<string>>();
List<string> str = new List<string>();
bool exist = false;
if (model.历史投标补充资料 != null && model.历史投标补充资料.Count() != 0)
{
url = model.历史投标补充资料;
}
string name = "";
if (Request.Form["picture"] != null)
{
name = Request.Form["picture"].ToString();
}
//long id = 0;
string which = "";
if (Request.Form["which"] != null)
{
which = Request.Form["which"].ToString();
}
string path = "";
for (int j = 0; j < Request.Files.Count; j++)
{
HttpPostedFileBase fileData = Request.Files[j];
string filePath = 上传管理.获取上传路径<验收单>(媒体类型.附件, 路径类型.不带域名根路径);
string fname = UploadImages_Ysd(fileData);
path += filePath + fname + "|";
ViewData["path"] = path;
ViewData["which"] = which;
str.Add(filePath + fname);
}
if (!string.IsNullOrWhiteSpace(name))
{
if (str.Count() != 0)
{
if (url.Count() != 0)
{
foreach (var i in url)
{
if (i.Key == name)
{
exist = true;
break;
}
}
if (!exist)
{
url.Add(name, str);
}
else
{
foreach (var m in str)
{
url[name].Add(m);
}
}
}
else
{
url.Add(name, str);
}
model.历史投标补充资料 = url;
}
用户管理.更新用户<供应商>(model);
}
}
catch
{
ViewData["path"] = "出错|";
}
return View();
}
示例14: settleAccount
private bool settleAccount(IClientDepartureInstruction instruction)
{
bool mgtFeeCharged = false;
instruction.Message = "";
if (instruction.CounterAccount == null)
{
instruction.Message = "Could not settle the account, look up the counter account.";
return false;
}
IManagementPeriod managementPeriod = instruction.Account.CurrentManagementFeePeriod;
if (managementPeriod != null)
{
IList<IManagementPeriodUnit> unitsNotCharged = managementPeriod.ManagementPeriodUnits
.Where(x => x.ManagementFee == null)
.OrderByDescending(x => x.StartDate)
.ToList();
Dictionary<int, Tuple<int, int>> quarterYears = new Dictionary<int, Tuple<int, int>>();
if (unitsNotCharged != null && unitsNotCharged.Count > 0)
{
BatchExecutionResults results = new BatchExecutionResults();
IManagementPeriodUnit lastUnit = unitsNotCharged.FirstOrDefault();
if (lastUnit != null && lastUnit.EndDate.Equals(managementPeriod.EndDate))
{
// get all quarter periods not yet charged
foreach (IManagementPeriodUnit unit in unitsNotCharged)
{
Tuple<int, int> quarterYear = new Tuple<int, int>(Util.GetQuarter(unit.EndDate), unit.EndDate.Year);
int key = quarterYear.Item2 * 100 + quarterYear.Item1;
if (!quarterYears.ContainsKey(key))
quarterYears.Add(key, quarterYear);
}
if (quarterYears.Count() == 0)
{
instruction.Message = "Could not charge management fee.";
return false;
}
else if (quarterYears.Count() == 1)
{
mgtFeeCharged = ManagementFeeOverviewAdapter.CreateMgtFeeTransactions(results, new int[] { lastUnit.ManagementPeriod.Key }, quarterYears.Values.First().Item2, quarterYears.Values.First().Item1, B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee, false);
}
else if (quarterYears.Count() > 1)
{
// Only charge last 2
// check if last 2 are chronological
int maxItemKey = quarterYears.Keys.OrderByDescending(x => x).ElementAt(0);
int prevItemKey = quarterYears.Keys.OrderByDescending(x => x).ElementAt(1);
Tuple<int, int> maxQuarterYear = quarterYears[maxItemKey];
if (Util.GetPreviousQuarterYear(maxQuarterYear.Item1, maxQuarterYear.Item2).Equals(quarterYears[prevItemKey]))
ManagementFeeOverviewAdapter.CreateMgtFeeTransactions(results, new int[] { lastUnit.ManagementPeriod.Key }, quarterYears[prevItemKey].Item2, quarterYears[prevItemKey].Item1, B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee, false);
mgtFeeCharged = ManagementFeeOverviewAdapter.CreateMgtFeeTransactions(results, new int[] { lastUnit.ManagementPeriod.Key }, quarterYears[maxItemKey].Item2, quarterYears[maxItemKey].Item1, B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee, false);
}
instruction.Message = ManagementFeeOverviewAdapter.FormatErrorsForCreateMgtFeeTransactions(results).Replace("<br/>", "");
}
else
{
// check if lastUnit is charged
IManagementPeriodUnit lastChargedUnit = managementPeriod.ManagementPeriodUnits
.Where(x => x.ManagementFee != null)
.OrderByDescending(x => x.StartDate)
.FirstOrDefault();
if (lastChargedUnit != null && lastChargedUnit.EndDate.Equals(managementPeriod.EndDate))
{
if (lastUnit == null)
mgtFeeCharged = true;
else
{
Tuple<int, int> lastQY = new Tuple<int, int>(Util.GetQuarter(lastChargedUnit.EndDate), lastChargedUnit.EndDate.Year);
Tuple<int, int> unChargedQY = new Tuple<int, int>(Util.GetQuarter(lastUnit.EndDate), lastUnit.EndDate.Year);
if (Util.GetPreviousQuarterYear(lastQY.Item1, lastQY.Item2).Equals(unChargedQY))
instruction.Message = "The previous quarter {0}{1} has not been charged";
else
mgtFeeCharged = true;
}
}
}
}
}
else
mgtFeeCharged = true;
if (mgtFeeCharged)
{
transferAllCash(instruction);
}
return true;
}
示例15: ManageDuplicateNames2
private void ManageDuplicateNames2(ref Dictionary<string, Dictionary<string,JSONObject>> attributes)
{
List<string> tmp = new List<string>();
foreach (KeyValuePair<string, Dictionary<string,JSONObject>> kvp in attributes)
{
try
{
attributes[kvp.Key].Add("display_name", kvp.Value["name"]);
}
catch (ArgumentException e)
{
//Do Nothing.
}
//If there are more than 1 user with a given name
if (attributes.Count(x => x.Value["name"].String.Equals(kvp.Value["name"].String)) > 1)
{
tmp = attributes.Where(x => x.Value["name"].String.Equals(kvp.Value["name"].String)).Select(x => x.Key).ToList();
for (int i = 0; i < tmp.Count; i++)
{
attributes[tmp[i]]["display_name"] = JSONObject.CreateFromString("\""+attributes[tmp[i]]["name"].String+ "_"+(i + 1).ToString()+"\"");
}
}
}
}