当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.Dictionary.TryGetValue方法代码示例

本文整理汇总了C#中System.Collections.Generic.System.Collections.Generic.Dictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Dictionary.TryGetValue方法的具体用法?C# System.Collections.Generic.Dictionary.TryGetValue怎么用?C# System.Collections.Generic.Dictionary.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic.System.Collections.Generic.Dictionary的用法示例。


在下文中一共展示了System.Collections.Generic.Dictionary.TryGetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            string errorCode = string.Empty;
            string res = string.Empty;
            string SourceCountryName = string.Empty;
            string TargetCountryName = string.Empty;
            string InputAmt = string.Empty;
            string OutputAmt = string.Empty;
            string jsonRes = string.Empty;

            Dictionary<string, string> values = new System.Collections.Generic.Dictionary<string,string>();

                string RawUrlx = "http://localhost/currency/?from=USD&to=EUR&q=1";
                NameValueCollection nm = HttpUtility.ParseQueryString(RawUrlx.Substring(RawUrlx.IndexOf("/?") + 2));

                SourceCountryName = nm.Get("from");
                TargetCountryName = nm.Get("to");
                InputAmt = nm.Get("q");
                nm.Add("ConvertedAmt",string.Empty);

                //Do All the good stuff here - validation

                var requestUri = string.Format("http://rate-exchange.appspot.com/currency?from={0}&to={1}&q={2}", Uri.EscapeDataString(SourceCountryName), Uri.EscapeDataString(TargetCountryName), Uri.EscapeDataString("1.23x"));

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
                try
                {
                    WebResponse response = request.GetResponse();
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                        jsonRes = reader.ReadToEnd();
                        values = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonRes);

                    }
                }
                catch (WebException ex)
                {
                    WebResponse errorResponse = ex.Response;
                    using (Stream responseStream = errorResponse.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                        String errorText = reader.ReadToEnd();
                    }
                    throw;
                }

                values.TryGetValue("err", out errorCode);
                values.TryGetValue("warning", out errorCode);
               // if (error)
                  //  return errorCode;

                bool successfulConv = values.TryGetValue("v", out OutputAmt);
        }
开发者ID:naveenve,项目名称:CurrencyExchange,代码行数:54,代码来源:Default.aspx.cs

示例2: UpdateParts

		protected virtual void UpdateParts(ContentItem target, ContentItem source)
		{

			List<string> keysTarget = new List<string>(target.GetChildren(new Collections.PartFilter()).Keys);
			List<string> keysSource = new List<string>(source.GetChildren(new Collections.PartFilter()).Keys);
			System.Collections.Generic.Dictionary<int, ContentItem> toCopy = new System.Collections.Generic.Dictionary<int, ContentItem>();

			bool bDelete = true;
			bool bAdd = true;


			foreach (string keyTarget in keysTarget)
			{
				ContentItem childTarget = target.Children[keyTarget];


				foreach (string keySource in keysSource)
				{
					ContentItem childSource = source.Children[keySource];

					if (childSource.TranslationKey == childTarget.TranslationKey)
					{
						UpdateContentItem(childTarget, childSource);
						childTarget.SortOrder = childSource.SortOrder;
						bDelete = false;
					}

				}

				if (bDelete)
				{
					_persister.Delete(childTarget);
					//N2.Context.Current.Resolve<N2.Edit.Trash.ITrashHandler>().Purge(childTarget);
				}
				else
					bDelete = true;
			}


			keysTarget = new List<string>(target.GetChildren(new Collections.PartFilter()).Keys);

			foreach (string keySource in keysSource)
			{
				ContentItem childSource = source.Children[keySource];

				foreach (string keyTarget in keysTarget)
				{
					ContentItem childTarget = target.Children[keyTarget];

					if (childSource.TranslationKey == childTarget.TranslationKey)
					{
						bAdd = false;
					}
				}

				if (bAdd)
				{
					childSource.ID = 0;
					childSource.Parent = null;
					toCopy.Add(source.Children.IndexOf(childSource), childSource);
				}
				else
					bAdd = true;

			}

			ContentItem copyChild;
			foreach (int key in toCopy.Keys)
			{
				if (toCopy.TryGetValue(key, out copyChild))
				{
					copyChild.InsertAt(target, key);
				}
			}

		}
开发者ID:andy4711,项目名称:n2cms,代码行数:76,代码来源:Updater.cs

示例3: ConvertCurrency

        public string ConvertCurrency(HttpContext context)
        {
            string errorCode = string.Empty;
            string res = string.Empty;
            string SourceCountryName = string.Empty;
            string TargetCountryName = string.Empty;
            string InputAmt = string.Empty;
            string OutputAmt = string.Empty;
            string jsonRes = string.Empty;
            string ConversionResult = string.Empty;

            Dictionary<string, string> values = new System.Collections.Generic.Dictionary<string, string>();

               // string RawUrlx = "http://localhost/currency/?from=USD&to=EUR&q=1";
            string RawUrlx = context.Request.RawUrl;
            NameValueCollection nm = HttpUtility.ParseQueryString(RawUrlx.Substring(RawUrlx.IndexOf("/?") + 2));

            // Populating the key-value object just for validation purposes
            SourceCountryName = nm.Get("from");
            TargetCountryName = nm.Get("to");
            InputAmt = nm.Get("q");
            nm.Add("ConvertedAmt", string.Empty);

            //Do All the good stuff here - validation

            // Here I could rather copy the request url and use it for the API post
            var requestUri = string.Format("http://rate-exchange.appspot.com/currency?from={0}&to={1}&q={2}", Uri.EscapeDataString(SourceCountryName), Uri.EscapeDataString(TargetCountryName), Uri.EscapeDataString(InputAmt));

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
            try
            {
                WebResponse response = request.GetResponse();
                using (Stream responseStream = response.GetResponseStream())
                {
                    // Reading the API call result, parsing the JSON object and populating the key-value object
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    jsonRes = reader.ReadToEnd();
                    values = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonRes);
                }
            }
            catch (WebException ex)
            {
                WebResponse errorResponse = ex.Response;
                using (Stream responseStream = errorResponse.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                    String errorText = reader.ReadToEnd();
                }
                throw;
            }

            //Validating Conversion API result
            values.TryGetValue("err", out errorCode);
            values.TryGetValue("warning", out errorCode);

            if (!String.IsNullOrEmpty(errorCode))
                return errorCode;

            values.TryGetValue("v", out OutputAmt);
                return OutputAmt;
        }
开发者ID:naveenve,项目名称:CurrencyExchange,代码行数:61,代码来源:CurrencyConverter.ashx.cs


注:本文中的System.Collections.Generic.System.Collections.Generic.Dictionary.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。