亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#實(shí)現(xiàn)將千分位字符串轉(zhuǎn)換成數(shù)字的方法

 更新時間:2014年08月04日 15:14:25   投稿:shichen2014  
這篇文章主要介紹了C#實(shí)現(xiàn)將千分位字符串轉(zhuǎn)換成數(shù)字的方法,很適合初學(xué)者更好的理解C#字符串原理,需要的朋友可以參考下

本文實(shí)例主要實(shí)現(xiàn)了C#將千分位字符串轉(zhuǎn)換成數(shù)字的方法,對C#初學(xué)者而言有一定的借鑒價值,主要內(nèi)容如下:

主要功能代碼如下:

/// <summary>
/// 將千分位字符串轉(zhuǎn)換成數(shù)字
/// 說明:將諸如"–111,222,333的千分位"轉(zhuǎn)換成-111222333數(shù)字
/// 若轉(zhuǎn)換失敗則返回-1
/// </summary>
/// <param name="thousandthStr">需要轉(zhuǎn)換的千分位</param>
/// <returns>數(shù)字</returns>
public static int ParseThousandthString(this string thousandthStr)
{
  int _value = -1;
  if (!string.IsNullOrEmpty(thousandthStr))
  {
 try
 {
   _value = int.Parse(thousandthStr, NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign);
 }
 catch (Exception ex)
 {
   _value = -1;
   Debug.WriteLine(string.Format("將千分位字符串{0}轉(zhuǎn)換成數(shù)字異常,原因:{0}", thousandthStr, ex.Message));
 }
  }
  return _value;
}

單元測試如下:

[TestMethod()]
public void ParseThousandthStringTest()
{
  string _thousandthStr = "-111,222,333";
  int _expected1 = -111222333;
  int _actual1 = StringToolV2.ParseThousandthString(_thousandthStr);
  Assert.AreEqual(_expected1, _actual1);
}

感興趣的讀者可以自己測試一下,希望對大家學(xué)習(xí)C#有所幫助!

相關(guān)文章

最新評論