Click here to Skip to main content
15,885,435 members
Home / Discussions / C#
   

C#

 
GeneralRe: help me in this code Pin
F-ES Sitecore3-Apr-16 4:15
professionalF-ES Sitecore3-Apr-16 4:15 
GeneralRe: help me in this code Pin
Pete O'Hanlon3-Apr-16 4:51
mvePete O'Hanlon3-Apr-16 4:51 
GeneralRe: help me in this code Pin
F-ES Sitecore3-Apr-16 4:56
professionalF-ES Sitecore3-Apr-16 4:56 
GeneralRe: help me in this code Pin
Ratul Thakur3-Apr-16 7:46
Ratul Thakur3-Apr-16 7:46 
GeneralRe: help me in this code Pin
Sascha Lefèvre3-Apr-16 13:11
professionalSascha Lefèvre3-Apr-16 13:11 
GeneralRe: help me in this code Pin
F-ES Sitecore3-Apr-16 22:38
professionalF-ES Sitecore3-Apr-16 22:38 
JokeRe: help me in this code Pin
Pete O'Hanlon3-Apr-16 22:57
mvePete O'Hanlon3-Apr-16 22:57 
AnswerRe: help me in this code Pin
Sascha Lefèvre2-Apr-16 5:10
professionalSascha Lefèvre2-Apr-16 5:10 
Please do use braces (brackets). As a beginner you shouldn't yet "experiment" with omitting them.

Please do not use labels ("HOME:"). Labels only make sense with the keyword goto and you should never, ever use goto until you exactly understand why I write this and are able to identify the 0,00001% case where goto might be excusable.

I assume you haven't yet learned about creating and calling own methods (which would be the best solution to letting the user retry entering a value).

So here's a comparatively good-style snippet for allowing the user to re-enter a value greater than zero if he entered a wrong value the first time or repeatedly:
C#
Console.WriteLine("Enter any number greater than 0: ");
string input = Console.ReadLine();
int value1;
while (!Int32.TryParse(input, out value1) || value1 <= 0)
{
    Console.WriteLine("Invalid input. Enter any number greater than 0: ");
    input = Console.ReadLine();
}
// at this point "value1" will contain a value greater than zero


Sidenote: In C#, local identifiers should be declared where you first need them, not all at the top of a method.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: help me in this code Pin
OriginalGriff2-Apr-16 6:16
mveOriginalGriff2-Apr-16 6:16 
GeneralRe: help me in this code Pin
Mycroft Holmes2-Apr-16 13:32
professionalMycroft Holmes2-Apr-16 13:32 
GeneralRe: help me in this code Pin
Sascha Lefèvre2-Apr-16 14:15
professionalSascha Lefèvre2-Apr-16 14:15 
GeneralRe: help me in this code Pin
Mycroft Holmes2-Apr-16 16:32
professionalMycroft Holmes2-Apr-16 16:32 
AnswerRe: help me in this code Pin
Suresh73-Apr-16 5:55
Suresh73-Apr-16 5:55 
QuestionInput string was not in a correct format as output in c# console application Pin
KittoKy2-Apr-16 1:48
KittoKy2-Apr-16 1:48 
AnswerRe: Input string was not in a correct format as output in c# console application Pin
OriginalGriff2-Apr-16 2:25
mveOriginalGriff2-Apr-16 2:25 
QuestionWrite/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib2-Apr-16 0:06
Mahbubur Rahman Rajib2-Apr-16 0:06 
AnswerRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
OriginalGriff2-Apr-16 0:09
mveOriginalGriff2-Apr-16 0:09 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib2-Apr-16 0:13
Mahbubur Rahman Rajib2-Apr-16 0:13 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
OriginalGriff2-Apr-16 0:19
mveOriginalGriff2-Apr-16 0:19 
AnswerRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Gerry Schmitz2-Apr-16 5:40
mveGerry Schmitz2-Apr-16 5:40 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib2-Apr-16 5:50
Mahbubur Rahman Rajib2-Apr-16 5:50 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Gerry Schmitz2-Apr-16 6:13
mveGerry Schmitz2-Apr-16 6:13 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib2-Apr-16 6:17
Mahbubur Rahman Rajib2-Apr-16 6:17 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Gerry Schmitz2-Apr-16 6:25
mveGerry Schmitz2-Apr-16 6:25 
GeneralRe: Write/Read ISBN of a book in NXP tag and Turn security ON/OFF Pin
Mahbubur Rahman Rajib4-Apr-16 22:19
Mahbubur Rahman Rajib4-Apr-16 22:19 

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.