Click here to Skip to main content
15,914,500 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why It displays error? Pin
sulomila31-Aug-17 21:36
sulomila31-Aug-17 21:36 
GeneralRe: Why It displays error? Pin
Richard MacCutchan31-Aug-17 21:46
mveRichard MacCutchan31-Aug-17 21:46 
GeneralRe: Why It displays error? Pin
sulomila31-Aug-17 22:35
sulomila31-Aug-17 22:35 
GeneralRe: Why It displays error? Pin
Richard MacCutchan31-Aug-17 23:02
mveRichard MacCutchan31-Aug-17 23:02 
QuestionHttp to Https Url redirection Pin
Member 1129085529-Aug-17 1:18
Member 1129085529-Aug-17 1:18 
AnswerRe: Http to Https Url redirection Pin
OriginalGriff29-Aug-17 1:42
mveOriginalGriff29-Aug-17 1:42 
GeneralRe: Http to Https Url redirection Pin
Member 1129085529-Aug-17 2:11
Member 1129085529-Aug-17 2:11 
GeneralRe: Http to Https Url redirection Pin
OriginalGriff29-Aug-17 2:28
mveOriginalGriff29-Aug-17 2:28 
Questionalt keywords problem Pin
Member 1337599027-Aug-17 22:27
Member 1337599027-Aug-17 22:27 
AnswerRe: alt keywords problem Pin
OriginalGriff27-Aug-17 23:32
mveOriginalGriff27-Aug-17 23:32 
QuestionTrying to Use the VCCodeModel Interface Pin
Richard Andrew x6427-Aug-17 13:17
professionalRichard Andrew x6427-Aug-17 13:17 
QuestionCoding Challenge Pin
Mycroft Holmes26-Aug-17 15:14
professionalMycroft Holmes26-Aug-17 15:14 
GeneralRe: Coding Challenge Pin
PIEBALDconsult26-Aug-17 15:26
mvePIEBALDconsult26-Aug-17 15:26 
GeneralRe: Coding Challenge Pin
Mycroft Holmes26-Aug-17 15:33
professionalMycroft Holmes26-Aug-17 15:33 
GeneralRe: Coding Challenge Pin
PIEBALDconsult26-Aug-17 16:14
mvePIEBALDconsult26-Aug-17 16:14 
QuestionRe: Coding Challenge Pin
PIEBALDconsult26-Aug-17 16:56
mvePIEBALDconsult26-Aug-17 16:56 
AnswerRe: Coding Challenge Pin
Mycroft Holmes26-Aug-17 22:20
professionalMycroft Holmes26-Aug-17 22:20 
AnswerRe: Coding Challenge Pin
BillWoodruff26-Aug-17 19:44
professionalBillWoodruff26-Aug-17 19:44 
AnswerRe: Coding Challenge Pin
Peter_in_278027-Aug-17 1:41
professionalPeter_in_278027-Aug-17 1:41 
AnswerRe: Coding Challenge Pin
Richard Deeming29-Aug-17 2:28
mveRichard Deeming29-Aug-17 2:28 
GeneralRe: Coding Challenge Pin
Mycroft Holmes4-Sep-17 21:06
professionalMycroft Holmes4-Sep-17 21:06 
SuggestionRe: Coding Challenge Pin
Richard Deeming5-Sep-17 1:55
mveRichard Deeming5-Sep-17 1:55 
GeneralRe: Coding Challenge Pin
Mycroft Holmes4-Sep-17 22:24
professionalMycroft Holmes4-Sep-17 22:24 
GeneralRe: Coding Challenge Pin
Pete O'Hanlon4-Sep-17 23:24
mvePete O'Hanlon4-Sep-17 23:24 
GeneralRe: Coding Challenge Pin
Richard Deeming5-Sep-17 2:04
mveRichard Deeming5-Sep-17 2:04 
It depends what you want the percentage change to be when one of the values is zero. Smile | :)

Assuming you want it to be 1, the ternary operator should do the trick:
C#
decimal average = lValues.Skip(1)
    .Zip(lValues, (second, first) => second == 0 ? 1 : (second - first) / second)
    .Average();

// Input:    { 100, 0, 120, 118, 126, 102 }
// % Change: { 1, 1, -0.0169491525423728813559322034, 0.0634920634920634920634920635, -0.2352941176470588235294117647 }
// Output:   0.3622497586605263574356296191




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.