本文整理汇总了C#中Dictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Add方法的具体用法?C# Dictionary.Add怎么用?C# Dictionary.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnSaveAsNew_Click
private void btnSaveAsNew_Click(object sender, EventArgs e)
{
try
{
string query;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("@Name", txtName.Text);
parameters.Add("@StartTime", dtpStart.Value.TimeOfDay);
parameters.Add("@EndTime", dtpEnd.Value.TimeOfDay);
query = @"INSERT INTO Periods (Name, StartTime, EndTime) VALUES (@Name, @StartTime, @EndTime);";
_PeriodID = SqlHelper.ExecteNonQuery(query, parameters);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.Close();
Central.MainForm.Focus();
foreach (DockContent item in Central.MainForm.Contents)
{
if (item is Periods)
{
((Periods)item).RefreshPeriods();
continue;
}
}
this.TabText = txtName.Text + " Details";
}
示例2: Start
void Start ()
{
player = transform.root.GetComponent<Player>();
SetCursorState(CursorState.Default);
resourceValues = new Dictionary<ResourceType, int>();
resourceLimits = new Dictionary<ResourceType, int>();
resourceValues.Add(ResourceType.Gold, 0);
resourceLimits.Add(ResourceType.Gold, 0);
resourceValues.Add(ResourceType.Nelther, 0);
resourceLimits.Add(ResourceType.Nelther, 0);
resourceValues.Add(ResourceType.Elynium, 0);
resourceLimits.Add(ResourceType.Elynium, 0);
resourceValues.Add(ResourceType.Population, 0);
resourceLimits.Add(ResourceType.Population, 0);
posBar = transform.FindChild("Frame1").FindChild("Frame").FindChild("BackGround").FindChild("Production").gameObject.transform.position;
transform.FindChild("Frame1").FindChild("UnitNameProduct").GetComponent<Text>().text = "";
transform.FindChild("Frame1").FindChild("HitText").GetComponent<Text>().text = "";
transform.FindChild("Frame1").FindChild("Object").gameObject.SetActive(false);
transform.FindChild("Frame1").FindChild("Frame").gameObject.SetActive(false);
transform.FindChild("Frame1").FindChild("UnitNameProduct").gameObject.SetActive(false);
for (int j = 1; j < 6; j++)
{
transform.FindChild("Frame1").FindChild("FrameUnit" + j.ToString()).gameObject.SetActive(false);
}
}
示例3: Deserialize
public static IncomingTransportMessage Deserialize(string messageId, Stream inputStream)
{
var headers = new Dictionary<string, string>();
var serializedMessageData = "";
using (var reader = new XmlTextReader(inputStream))
{
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.Read(); // read <root>
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
var elementName = reader.Name;
reader.Read(); // read the child;
while (reader.NodeType == XmlNodeType.Element)
{
// likely an empty header element node
headers.Add(elementName, reader.Value);
elementName = reader.Name;
reader.Read(); // read the child;
}
if (string.Equals(elementName, "body", StringComparison.InvariantCultureIgnoreCase) && reader.NodeType == XmlNodeType.CDATA)
{
serializedMessageData = reader.Value;
}
else if (reader.NodeType == XmlNodeType.Text)
{
headers.Add(elementName, reader.Value);
}
}
}
}
return new IncomingTransportMessage(messageId, headers, serializedMessageData);
}
示例4: DatabaseGenerationAssemblyLoader
internal DatabaseGenerationAssemblyLoader(Project project, string vsInstallPath)
{
_assembliesInstalledUnderVisualStudio = new Dictionary<string, string>();
// For these DLLs we should use the version pre-installed under the VS directory,
// not whatever reference the project may have
_assembliesInstalledUnderVisualStudio.Add(
"ENTITYFRAMEWORK", Path.Combine(vsInstallPath, "EntityFramework.dll"));
_assembliesInstalledUnderVisualStudio.Add(
"ENTITYFRAMEWORK.SQLSERVER", Path.Combine(vsInstallPath, "EntityFramework.SqlServer.dll"));
_assembliesInstalledUnderVisualStudio.Add(
"ENTITYFRAMEWORK.SQLSERVERCOMPACT", Path.Combine(vsInstallPath, "EntityFramework.SqlServerCompact.dll"));
_projectReferenceLookup = new Dictionary<string, Reference3>();
_websiteReferenceLookup = new Dictionary<string, AssemblyReference>();
if (project != null)
{
var vsProject = project.Object as VSProject2;
var vsWebSite = project.Object as VSWebSite;
if (vsProject != null)
{
_isWebsite = false;
CacheProjectReferences(vsProject);
}
else if (vsWebSite != null)
{
_isWebsite = true;
CacheWebsiteReferences(vsWebSite);
}
}
}
示例5: Add
/// <summary>
/// 11、 添加指标
/// </summary>
/// <param name="name">指标名称</param>
/// <param name="itype">输入方式</param>
/// <param name="vtype">值类型</param>
/// <param name="editbypat">是否可由病人编辑</param>
/// <param name="hospitalid">医院id</param>
/// <param name="cateid">病例分类id</param>
/// <param name="val">值序列,以数组形式传递,可为空</param>
/// <returns></returns>
/// Jack Ding
public TermAddResponse Add(string name, int itype, int vtype, int editbypat, int hospitalid, int cateid, double[] val)
{
string strResponse = string.Empty;
TermAddResponse response = new TermAddResponse();
try
{
Dictionary<string, string> sPara = new Dictionary<string, string>();
sPara.Add("name", name);
sPara.Add("itype", itype.ToString());
sPara.Add("vtype", vtype.ToString());
sPara.Add("editbypat", editbypat.ToString());
sPara.Add("hospitalid", hospitalid.ToString());
//val参数不知道如何添加
strResponse = F8YLSubmit.BuildRequest(sPara, "term/add");
response = JsonHelper.DeserializeJsonToObject<TermAddResponse>(strResponse);
return response;
}
catch
{
throw;
}
}
示例6: Test_Serialize_Dictionary_02
public static void Test_Serialize_Dictionary_02(DictionaryRepresentation dictionaryRepresentation)
{
// json Dictionary
// DictionaryRepresentation.Dynamic or DictionaryRepresentation.Document
// { "toto1" : "tata1", "toto2" : "tata2" }
// DictionaryRepresentation.ArrayOfArrays
// [["toto1", "tata1"], ["toto2", "tata2"]]
// DictionaryRepresentation.ArrayOfDocuments
// [{ "k" : "toto1", "v" : "tata1" }, { "k" : "toto2", "v" : "tata2" }]
Trace.WriteLine();
Trace.WriteLine("Test_Serialize_Dictionary_02");
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("toto1", "tata1");
dictionary.Add("toto2", "tata2");
//DictionaryRepresentation dictionaryRepresentation = DictionaryRepresentation.ArrayOfDocuments;
Trace.WriteLine("DictionaryRepresentation : {0}", dictionaryRepresentation);
Trace.WriteLine("Dictionary json :");
string json = dictionary.ToJson(new DictionarySerializationOptions(dictionaryRepresentation));
Trace.WriteLine(json);
Trace.WriteLine("Deserialize json :");
Dictionary<string, string> dictionary2 = BsonSerializer.Deserialize<Dictionary<string, string>>(json);
string json2 = dictionary2.ToJson(new DictionarySerializationOptions(dictionaryRepresentation));
Trace.WriteLine(json2);
Trace.WriteLine("comparison of Dictionary json and Deserialize json : {0}", json == json2 ? "identical" : "different");
}
示例7: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method GetEnumerator in ValueCollection Generic IEnumerable 1");
try
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("str1", "Test1");
dic.Add("str2", "Test2");
IEnumerable<string> ienumer = (IEnumerable<string>)new Dictionary<string, string>.ValueCollection(dic);
IEnumerator<string> ienumerator = ienumer.GetEnumerator();
Dictionary<string, string>.Enumerator dicEnumer = dic.GetEnumerator();
while (ienumerator.MoveNext() && dicEnumer.MoveNext())
{
if (!ienumerator.Current.Equals(dicEnumer.Current.Value))
{
TestLibrary.TestFramework.LogError("001", "the ExpecResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例8: Index
//
// GET: /Home/
public ActionResult Index()
{
var beneficiaries = _unitOfWork.Beneficiaries.GetAll();
Dictionary<string, decimal> totals = new Dictionary<string, decimal>();
const decimal TARGET = 600000;
totals.Add("Target", TARGET);
List<Payment> payments = _unitOfWork.Payments.GetPaymentWithCurrency().ToList();
var posted = payments.Where(p => p.Locked).Sum(p => p.Amount * p.Currency.ExchangeRate);
totals.Add("Posted", posted);
var total = payments.Sum(p => p.Amount * p.Currency.ExchangeRate);
totals.Add("Total", total);
ViewBag.Posted = totals["Posted"];
ViewBag.Total = totals["Total"];
ViewBag.Target = totals["Target"];
ViewBag.Percentage = Convert.ToInt32((ViewBag.Total / ViewBag.Target) * 100);
return View(beneficiaries);
}
示例9: CreateMenu
private void CreateMenu()
{
Sites = new Dictionary<string, string>();
var root = "../Form/";
Sites.Add(root + "Start.aspx", Resources.Default.home);
Sites.Add(root + "Uebersicht.aspx", Resources.Default.accountMovements);
Sites.Add(root + "Kategorie.aspx", Resources.Default.Overview);
if (SessionManager.CurrentUser.ISADMIN == true)
{
Sites.Add(root + "Admin/Admin.aspx", Resources.Default.admin);
}
var script = string.Empty;
foreach (var str in Sites)
{
script = string.Concat(script,
"haushaltsRechner.client.menuPoint('",
str.Key,
"','",
str.Value,
"','",
MainMenu.ClientID,
"');");
}
ScriptManager.RegisterStartupScript(this, GetType(), "STARTUPSCRIPTCONTENTMASTER_" + ClientID, script, true);
}
示例10: SendLetter
public void SendLetter(UpdateLetter updateLetter)
{
var letter = updateLetter.CreateLetter();
letter.ReplyTime = SqlDateTime.MinValue.Value;
using (var content = new DefaultContext())
{
content.Letters.Add(letter);
content.SaveChanges();
}
var dic = new Dictionary<string, string>();
dic.Add("ActionName", "Reply");
dic.Add("letter", letter.ToJson());
var resString = HttpWebResponseUtility.CreatePostHttpResponse("http://second.eagle.com/api/Message", dic.ToJson(), 30000);
if (string.IsNullOrEmpty(resString) || resString == "0")
{
Flag = false;
Message = "消息无响应";
return;
}
var result = resString.ToDeserialize<Cells>();
if (!result.Flag)
{
Flag = false;
Message = result.Message;
return;
}
Flag = true;
}
示例11: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method CopyTo in the ValueCollection 2");
try
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("str1", "Test1");
dic.Add("str2", "Test2");
Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic);
string[] TVals = new string[SIZE];
values.CopyTo(TVals, 5);
string strVals = null;
for (int i = 0; i < TVals.Length; i++)
{
if (TVals[i] != null)
{
strVals += TVals[i].ToString();
}
}
if (TVals[5].ToString() != "Test1" || TVals[6].ToString() != "Test2" || strVals != "Test1Test2")
{
TestLibrary.TestFramework.LogError("003", "the ExpecResult is not the ActualResult");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例12: GetAccessToken
public bool GetAccessToken(string code)
{
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("code", code);
args.Add("client_id", AuthInfo.Client_ID);
args.Add("client_secret", AuthInfo.Client_Secret);
args.Add("redirect_uri", "urn:ietf:wg:oauth:2.0:oob");
args.Add("grant_type", "authorization_code");
string response = SendRequest(HttpMethod.POST, "https://accounts.google.com/o/oauth2/token", args);
if (!string.IsNullOrEmpty(response))
{
OAuth2Token token = JsonConvert.DeserializeObject<OAuth2Token>(response);
if (token != null && !string.IsNullOrEmpty(token.access_token))
{
token.UpdateExpireDate();
AuthInfo.Token = token;
return true;
}
}
return false;
}
示例13: ModScriptInterpreterContext
/// <summary>
/// A simple construtor that initializes the object with the given dependencies.
/// </summary>
/// <param name="p_msfFunctions">The object that proxies the script function calls
/// out of the sandbox.</param>
public ModScriptInterpreterContext(ModScriptFunctionProxy p_msfFunctions)
{
Variables = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
FunctionProxy = p_msfFunctions;
Variables.Add("NewLine", Environment.NewLine);
Variables.Add("Tab", "\t");
}
示例14: feed
public override Dictionary<string, object> feed(
Dictionary<string, object> data)
{
data.Add("text", Text);
data.Add("link", Link);
return data;
}
示例15: Get
//// GET api/<controller>
//public IEnumerable<string> Get()
//{
// return new string[] { "value1", "value2" };
//}
//// GET api/<controller>/5
//public string Get(int id)
//{
// return "value";
//}
//// POST api/<controller>
//public void Post([FromBody]string value)
//{
//}
//// PUT api/<controller>/5
//public void Put(int id, [FromBody]string value)
//{
//}
//// DELETE api/<controller>/5
//public void Delete(int id)
//{
//}
public Dictionary<string, Boolean> Get()
{
Dictionary<string, Boolean> perms = new Dictionary<string, Boolean>();
using (ServerApplicationContext ctx = ServerApplicationContext.CreateContext())
{
var currentUser = ctx.Application.User;
if (currentUser.IsAuthenticated)
{
perms.Add(Permissions.SecurityAdministration,
currentUser.HasPermission(Permissions.SecurityAdministration));
currentUser.AddPermissions(Permissions.SecurityAdministration);
foreach (Permission perm in ctx.DataWorkspace.SecurityData.Permissions)
{
if (perm.Id != Permissions.SecurityAdministration)
{
perms.Add(perm.Id, currentUser.HasPermission(perm.Id));
}
}
}
}
return perms;
}