【原創】-- C# 點滴積累 -- String

索引:html

目錄索引ide

1、string.Format()spa

  將【數字字符串】轉爲兩位小數顯示的字符串:code

1                 dt = dtResult.Select(it => new CommodityPriceLimitEntity
2                 {
3                     CommodityId = it.CommodityId.ToString(),
4                     CommodityName = it.CommodityName.ToString(),
5                     CommodityCode = it.CommodityCode.ToString(),
6                     Price = string.Format("{0:F2}", it.Price)
7                 }).ToList();
C# code

------------------------------------------------------------------------------------------------------------------------------orm

------------------------------------------------------------------------------------------------------------------------------htm

------------------------------------------------------------------------------------------------------------------------------blog

  方法一:將時間轉爲【yyyy/MM/dd HH:mm:ss】 格式顯示字符串:索引

1                     if (!string.IsNullOrWhiteSpace(item.EffectiveTimeEnd))  // 生效結束時間 
2                     {
3                         item.EffectiveTimeEnd = string.Format("{0}", item.EffectiveTimeEnd);
4                     }
C# code

------------------------------------------------------------------------------------------------------------------------------ci

------------------------------------------------------------------------------------------------------------------------------字符串

  方法二:將時間轉爲【yyyy/MM/dd HH:mm:ss】 格式顯示字符串: 

 1                         //
 2                         mb.CommodityCode = ma.CommodityCode;
 3                         mb.MaxPrice = ma.MaxPrice.ToString(".00");
 4                         mb.MinPrice = ma.MinPrice.ToString(".00");
 5                         mb.PriceLimitStart = string.Format(ma.EffectiveTimeStart.ToString(), "yyyy-MM-dd HH:mm:ss");
 6                         mb.PriceLimitEnd = string.Format(ma.EffectiveTimeEnd.ToString(), "yyyy-MM-dd HH:mm:ss");
 7 
 8                         //
 9                         result.Add(mb);
10                     }
11                 }
C# code

------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------

 

 

2、.ToString()

  將【數字字符串】轉爲兩位小數顯示的字符串:

1             if (dt != null
2                 && dt.Count > 0)
3             {
4                 foreach (var item in dt)
5                 {
6                     item.StandardPrice = Convert.ToDecimal(item.StandardPrice).ToString(".00");
7                     item.MinPrice = Convert.ToDecimal(item.MinPrice).ToString(".00");
8                 }
9             }
C# code

------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------

  便捷避免【字符串空引用】.ToString()

 1             result = result.Select(it => new ChannelCommodityPriceSearchResultDTO
 2             {
 3                 CompanyId = it.CompanyId.ToString(),
 4                 CompanyName = it.CompanyName.ToString(),
 5                 CommodityPriceId = it.CommodityPriceId.ToString(),
 6                 FirstChannelName = it.FirstChannelName.ToString(),
 7                 SecondChannelID = it.SecondChannelID.ToString(),
 8                 SecondChannelName = it.SecondChannelName.ToString(),
 9                 CommodityCode = it.CommodityCode.ToString(),
10                 CommodityName = it.CommodityName.ToString(),
11                 MainCommodityCode = it.MainCommodityCode.ToString(),
12                 GlobalCategoryName = it.GlobalCategoryName.ToString(),
13                 MainCategoryName = it.MainCategoryName.ToString(),
14                 SubCategoryName = it.SubCategoryName.ToString(),
15                 SubCategoryID = (it.SubCategoryID ?? "").ToString(),
16                 Price = it.Price.ToString()
17             }).ToList();
C# code

------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------

 

 

 

持續更新中~~

 

 

                                         蒙

                                    2017-08-03 13:58 週四

                                    2017-08-11  04:45 週五  更新於深夜系統發佈過程當中~~

                                    2017-08-17  09:35 週四  

相關文章
相關標籤/搜索