Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: Somewhat embarrassed: how do I get the dotnet framework? Pin
Septimus Hedgehog8-Dec-12 9:33
Septimus Hedgehog8-Dec-12 9:33 
Questionneed help please Pin
Gondzer7-Dec-12 23:58
Gondzer7-Dec-12 23:58 
AnswerRe: need help please Pin
Mycroft Holmes8-Dec-12 1:02
professionalMycroft Holmes8-Dec-12 1:02 
GeneralRe: need help please Pin
Gondzer8-Dec-12 1:09
Gondzer8-Dec-12 1:09 
GeneralRe: need help please Pin
Mycroft Holmes8-Dec-12 1:41
professionalMycroft Holmes8-Dec-12 1:41 
AnswerRe: need help please Pin
vr9999999998-Dec-12 1:04
vr9999999998-Dec-12 1:04 
GeneralRe: need help please Pin
Gondzer8-Dec-12 1:17
Gondzer8-Dec-12 1:17 
AnswerRe: need help please Pin
OriginalGriff8-Dec-12 2:03
mveOriginalGriff8-Dec-12 2:03 
Just to add to what the others have said - you don't want to do it like that anyway!
C#
for (int i = 0; i < 5; i++)
{
   i = int.Parse(Console.ReadLine());
}

Since i is both the loop control variable and the place you store the value the user entered, if the user enters 4 or above as his first number, it will exit the loop immediately.
You need to separate these two functions into two variables, as well as using an array or List<int>

BTW: It is considered a bad idea to use "magic numbers" such as "5" in your code - when you move to an array, it is too easy to later change one and not the other, causing your application to fail, or crash:
C#
int[] inp = new int[5];
for (int i = 0; i < 5; i++)
   {
   inp[i] = int.Parse(Console.ReadLine());
   }

would be better as:
C#
const int elements = 5;
int[] inp = new int[elements];
for (int i = 0; i < elements; i++)
    {
    inp[i] = int.Parse(Console.ReadLine());
    }
That way, you only have to change the number of elements in a single place, and it all works perfectly.

And as a final thing, if your user enters an alphabetic character instead of a digit, your program will crash. You should always check your user input - they do enter rubbish quite often! Laugh | :laugh:


[edit]Typos - OriginalGriff[/edit]
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

AnswerRe: need help please Pin
Jibesh9-Dec-12 22:03
professionalJibesh9-Dec-12 22:03 
QuestionInsert Data to Master/Detail table in Sqlserver 2005 from C# with Foreign key in Detail table Pin
ahmed_one7-Dec-12 20:31
ahmed_one7-Dec-12 20:31 
AnswerRe: Insert Data to Master/Detail table in Sqlserver 2005 from C# with Foreign key in Detail table Pin
Eddy Vluggen8-Dec-12 2:49
professionalEddy Vluggen8-Dec-12 2:49 
GeneralRe: Insert Data to Master/Detail table in Sqlserver 2005 from C# with Foreign key in Detail table Pin
ahmed_one8-Dec-12 22:55
ahmed_one8-Dec-12 22:55 
GeneralRe: Insert Data to Master/Detail table in Sqlserver 2005 from C# with Foreign key in Detail table Pin
Eddy Vluggen8-Dec-12 23:59
professionalEddy Vluggen8-Dec-12 23:59 
QuestionContinuous listening of COM port for detecting MODEM?? Pin
shubhamjoshi7-Dec-12 19:59
shubhamjoshi7-Dec-12 19:59 
AnswerRe: Continuous listening of COM port for detecting MODEM?? Pin
vr9999999998-Dec-12 1:08
vr9999999998-Dec-12 1:08 
GeneralRe: Continuous listening of COM port for detecting MODEM?? Pin
Mycroft Holmes8-Dec-12 1:42
professionalMycroft Holmes8-Dec-12 1:42 
AnswerRe: Continuous listening of COM port for detecting MODEM?? Pin
Andy41111-Dec-12 1:51
Andy41111-Dec-12 1:51 
Questionreturning the largest int variable Pin
RichB377-Dec-12 12:54
RichB377-Dec-12 12:54 
AnswerRe: returning the largest int variable Pin
PIEBALDconsult7-Dec-12 14:15
mvePIEBALDconsult7-Dec-12 14:15 
GeneralRe: returning the largest int variable Pin
RichB377-Dec-12 15:00
RichB377-Dec-12 15:00 
GeneralRe: returning the largest int variable Pin
Brisingr Aerowing7-Dec-12 17:03
professionalBrisingr Aerowing7-Dec-12 17:03 
AnswerRe: returning the largest int variable Pin
Dave Kreskowiak7-Dec-12 18:41
mveDave Kreskowiak7-Dec-12 18:41 
GeneralRe: returning the largest int variable Pin
RichB377-Dec-12 18:51
RichB377-Dec-12 18:51 
AnswerRe: returning the largest int variable Pin
CommDev8-Dec-12 23:52
CommDev8-Dec-12 23:52 
QuestionManual serialization of a class that contains the same class Pin
nadavst7-Dec-12 11:34
nadavst7-Dec-12 11:34 

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.