Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
private async Task GeReceipts()
        {
            receiptData = new List();
            UserDialogs.Instance.ShowLoading("", MaskType.Clear);
            receiptData = await GetReceiptsData.GetReceipts_Data(olcID, _status);
            UserDialogs.Instance.HideLoading();
            if (receiptData.Count() >= 0)
            {
                countrows = receiptData.Count();
                _msdins = receiptData.Select(element => element.MSIDN).ToArray();
                _price = receiptData.Select(element => element.Price).ToArray();
                return true;
            }
            else
                return false;
        }


What I have tried:

Code for getting sum of _price..
Posted
Updated 7-May-18 3:06am
v2

1 solution

You can use Enumerable.Sum Method (System.Linq)[^]:

_price = receiptData.Sum(element => element.Price);
 
Share this answer
 
Comments
Maciej Los 7-May-18 8:24am    
5ed!
Member 13591965 9-May-18 4:00am    
_price = receiptData.Sum(element => element.Price);

not working showing error
[no name] 9-May-18 4:02am    
What is the error? Is _price of the same type as element.Price?
Member 13591965 9-May-18 4:10am    
Cannot implicitly convert type 'string' to 'long?'

Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
[no name] 9-May-18 4:28am    
That means element.Price is a string. You can convert it to a Decimal first using Decimal.Parse. The result will be a Decimal too then.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900