خطا در تبدیل object به float
سلام. من میخوام مقدار یه object رو به float تبدیل کنم.
خطا میده که cast is not valid
کدم اینه.
public float GetStock(int ProductID, int StoreID)
{
var stock = new ObjectParameter("Stock", typeof(float));
ProductStock(ProductID, StoreID, stock);
return (float)(stock.Value);
}
مثلا وقتی مقدار stock.Value برابر 66.0 هست باز هم این خطا رو میده
چکار باید کرد؟
نقل قول: خطا در تبدیل object به float
نقل قول:
نوشته شده توسط
resident
سلام. من میخوام مقدار یه object رو به float تبدیل کنم.
خطا میده که cast is not valid
کدم اینه.
public float GetStock(int ProductID, int StoreID)
{
var stock = new ObjectParameter("Stock", typeof(float));
ProductStock(ProductID, StoreID, stock);
return (float)(stock.Value);
}
مثلا وقتی مقدار stock.Value برابر 66.0 هست باز هم این خطا رو میده
چکار باید کرد؟
در خط آخر به شکل زیر عمل کنید:
return (float)Convert.ToSingle(stock.Value);