Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
GeneralRe: What is good practice Pin
BillWoodruff30-Oct-18 17:08
professionalBillWoodruff30-Oct-18 17:08 
AnswerRe: What is good practice Pin
Bernhard Hiller30-Oct-18 22:49
Bernhard Hiller30-Oct-18 22:49 
QuestionUsing InPlaceBitmapMetadataWriter To Write Keywords Failing on Photos from Recent Cameras Pin
richmhouse29-Oct-18 7:37
richmhouse29-Oct-18 7:37 
QuestionScrolling reset when application regains focus Pin
pr1mem0ver29-Oct-18 2:58
pr1mem0ver29-Oct-18 2:58 
AnswerRe: Scrolling reset when application regains focus Pin
BillWoodruff29-Oct-18 11:55
professionalBillWoodruff29-Oct-18 11:55 
QuestionRookie needs help with array Pin
Member 1398787027-Oct-18 5:28
Member 1398787027-Oct-18 5:28 
AnswerRe: Rookie needs help with array Pin
Richard MacCutchan27-Oct-18 5:54
mveRichard MacCutchan27-Oct-18 5:54 
AnswerRe: Rookie needs help with array Pin
OriginalGriff27-Oct-18 6:12
mveOriginalGriff27-Oct-18 6:12 
Take your errors one-by-one and look at them closely. If you double click on an error message in the "Error List" pane, it will take you to the line it refers to. The first one will be in your Average Method:
C#
private double Average(double[] iArray)
    {
    double total = 0.0;
    double average;

    for (double index = 0; index < iArray.Length; index++)
        {
        total += iArray[index];
        }

    average = (double)total / iArray.Length;
    return average;
    }
And will say:
Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

What that is saying is that you are using a double value where an int is expected, and that the system will not automatically change that for you because it will result in lost information. And that's true: if you convert the double value 1.5 to an int it will "throw away" the half and leave you with 1. The system wants to be sure you meant to do that, so it gives you an error. And array indexes are always either integer or strings, so you can;t use a double between the square brackets.
You can do what it suggests and explicitly cast it:
C#
total += iArray[(int)index];
But that's a poor solution: change the index to an integer and all will be fine:
C#
private double Average(double[] iArray)
    {
    double total = 0.0;
    double average;

    for (int index = 0; index < iArray.Length; index++)
        {
        total += iArray[index];
        }

    average = total / iArray.Length;
    return average;
    }
The error message will vanish, and you can move on to the next.
Which is the Lowest method, and exactly the same problem!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Rookie needs help with array Pin
Member 1398787028-Oct-18 12:39
Member 1398787028-Oct-18 12:39 
GeneralRe: Rookie needs help with array Pin
OriginalGriff28-Oct-18 20:58
mveOriginalGriff28-Oct-18 20:58 
Question[Solved]How i deserialize a specific JSON with Newtonsoft Pin
Kapparina26-Oct-18 13:35
Kapparina26-Oct-18 13:35 
AnswerRe: How i deserialize a specific JSON with Newtonsoft Pin
josda100026-Oct-18 17:45
josda100026-Oct-18 17:45 
GeneralRe:How i deserialize a specific JSON with Newtonsoft Pin
Kapparina26-Oct-18 18:11
Kapparina26-Oct-18 18:11 
GeneralRe:How i deserialize a specific JSON with Newtonsoft Pin
josda100029-Oct-18 6:10
josda100029-Oct-18 6:10 
QuestionHow do i do this assignment???? Pin
C#NoobHelpMe25-Oct-18 16:49
C#NoobHelpMe25-Oct-18 16:49 
AnswerRe: How do i do this assignment???? Pin
OriginalGriff25-Oct-18 19:29
mveOriginalGriff25-Oct-18 19:29 
AnswerRe: How do i do this assignment???? Pin
Richard MacCutchan25-Oct-18 21:23
mveRichard MacCutchan25-Oct-18 21:23 
JokeRe: How do i do this assignment???? Pin
Peter_in_278025-Oct-18 21:50
professionalPeter_in_278025-Oct-18 21:50 
GeneralRe: How do i do this assignment???? Pin
Richard MacCutchan25-Oct-18 21:52
mveRichard MacCutchan25-Oct-18 21:52 
GeneralRe: How do i do this assignment???? Pin
OriginalGriff26-Oct-18 0:47
mveOriginalGriff26-Oct-18 0:47 
AnswerRe: How do i do this assignment???? Pin
Pete O'Hanlon26-Oct-18 1:40
mvePete O'Hanlon26-Oct-18 1:40 
GeneralRe: How do i do this assignment???? Pin
Eddy Vluggen26-Oct-18 8:33
professionalEddy Vluggen26-Oct-18 8:33 
QuestionBackground worker release resources Pin
udi altman24-Oct-18 8:00
udi altman24-Oct-18 8:00 
AnswerRe: Background worker release resources Pin
OriginalGriff24-Oct-18 20:01
mveOriginalGriff24-Oct-18 20:01 
AnswerRe: Background worker release resources Pin
Eddy Vluggen25-Oct-18 0:45
professionalEddy Vluggen25-Oct-18 0:45 

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.