本文介绍了如何获取变量的列表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要列表值变量为十进制unil = lst.Unit等等..

请帮帮我out ..



Hi ,

I need list value to variables as decimal unil=lst.Unit and so on..
Please help me out ..

Quote:



var lst = BusinessLayer.restdetailsBAL.Instance.GetRestDetails(Convert.ToInt32(lblID.Text))。选择(q => new {

Unit = q.Unit,

SelPrice = q.SellPrice,

Batch = q.Batch,

Expiry = q.Expiry

})。ToList();


var lst = BusinessLayer.restdetailsBAL.Instance.GetRestDetails(Convert.ToInt32(lblID.Text)).Select(q=> new {
Unit=q.Unit,
SelPrice=q.SellPrice,
Batch=q.Batch,
Expiry=q.Expiry
}).ToList();





我尝试过:



我怎么试试: -

string s = lst.Select(q => q.Unit);

但是有(不能隐式转换类型) 'System.Collections.Generic.IEnumerable< decimal>'to'string');



What I have tried:

how every i try :-
string s = lst.Select(q => q.Unit);
but there is(Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<decimal>' to 'string');

推荐答案

var item = BusinessLayer.restdetailsBAL.Instance.GetRestDetails(Convert.ToInt32(lblID.Text)).Select(q => new
         {
             Unit = q.Unit,
             SelPrice = q.SellPrice,
             Batch = q.Batch,
             Expiry = q.Expiry
         }).FirstOrDefault();

         if (item != null)
         {
             string unit = item.Unit;
             var SelPrice = item.SelPrice;
             var Batch = item.Batch;
             var Expiry = item.Expiry;
         }





参考这些

[]

[]

]



refer these
FirstOrDefault[^]
SingleOrDefault[^]
Difference Between First() and FirstOrDefault() in LINQ[^]


这篇关于如何获取变量的列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:10