I have a LINQ query like this:
var q = from p in m.TblOzvs.AsEnumerable()
where (p.OzviyatNumber == txtSearch.Text)
select new mylist
{
Col1 = p.OzviyatNumber.ToString(),
Col2 = p.Name,
Col3 = Calculate._RPMajmoSoodeGhest(p.OzviyatNumber)[1],
Col4 = Calculate._RPMajmoSoodeGhest(p.OzviyatNumber)[0]
};
As you can see, for Col3 and Col4 I need to call a function that returns an array of strings where string[1] is for Col3 and string[0] is for Col4.
I was wondering if there is any way to call Calculate._RPMajmoSoodeGhest() 1 time and use it for both Col3 and Col4?
You can use 'let' to define a quantity that you can reference in the 'select' portion of the query:
var q = from p in m.TblOzvs.AsEnumerable()
where (p.OzviyatNumber == txtSearch.Text)
let calcVal = Calculate._RPMajmoSoodeGhest(p.OzviyatNumber)
select new mylist
{
Col1 = p.OzviyatNumber.ToString(),
Col2 = p.Name,
Col3 = calcVal[1],
Col4 = calcVal[0]
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With