本文介绍了我如何才能将字符串逗号分隔符值转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string _shipId = string.Empty;
string[] _ShipIIds;
decimal[] _SelectShipIId;

_ShipIIds = new string[_shipId.Count()];
_SelectShipIId = new decimal[_ShipIIds.Count()];
_ShipIIds = _shipId.Split(',');

for (int i = 0; i < _ShipIIds.Count(); i++)
{
    _SelectShipIId[i] =Convert.ToDecimal(_ShipIIds[i]);
}

what am having the value in _shipIIds the same value am getting the _selectShipIId also but in _ShipIIds is getting count 2 and _SelectShipIid is getting the count 3.

How i can reduce the _SelectShipIID count is 2..

_SelectShipIId=new decimal[_ShipId.count()];
_SelectShipIId=_ShipId.split(',');


从split函数抛出异常.

无法将类型string []隐式转换为十进制..

请帮助我解决这个问题..


from the split function its throw the exception..

cannot implicitly convert type string[] to decimal..

Please help me to solve this..

推荐答案

string _shipId = string.Empty;
 decimal[] _SelectShipIId;
 foreach (ShippingCarrierDTO _ship in _site.ShipVia)
 {
   if (string.IsNullOrEmpty(_shipId))
 {
  _shipId = Convert.ToString(_ship.ShipIId);
 }
 else
 {
   _shipId += "," + Convert.ToString(_ship.ShipIId);
 }
}

 _SelectShipIId =new decimal[_shipId.Length];
 for (int i = 0; i = _shipId.ToString.Split(",").count-1; i++)
 {
  _SelectShipIId[i] = CDec(_shipId.ToString.Split(",")(i);
 }


这篇关于我如何才能将字符串逗号分隔符值转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 14:58