Click here to Skip to main content
15,900,906 members
Home / Discussions / C#
   

C#

 
SuggestionRe: Help solve the question in a language C #? Pin
Richard MacCutchan25-Nov-13 5:49
mveRichard MacCutchan25-Nov-13 5:49 
AnswerRe: Help solve the question in a language C #? Pin
OriginalGriff25-Nov-13 6:01
mveOriginalGriff25-Nov-13 6:01 
AnswerRe: Help solve the question in a language C #? Pin
Abhinav S25-Nov-13 6:33
Abhinav S25-Nov-13 6:33 
GeneralRe: Help solve the question in a language C #? Pin
harold aptroot25-Nov-13 6:44
harold aptroot25-Nov-13 6:44 
AnswerRe: Help solve the question in a language C #? Pin
DaveyM6926-Nov-13 5:27
professionalDaveyM6926-Nov-13 5:27 
QuestionPassing a value from a method to the Main() Pin
Member 982953625-Nov-13 5:10
Member 982953625-Nov-13 5:10 
AnswerRe: Passing a value from a method to the Main() Pin
Richard MacCutchan25-Nov-13 5:48
mveRichard MacCutchan25-Nov-13 5:48 
AnswerRe: Passing a value from a method to the Main() Pin
OriginalGriff25-Nov-13 6:10
mveOriginalGriff25-Nov-13 6:10 
As Richard says, Main needs to be static or it won't be executed.
But...you never assign a value to drawerValue in a Main method, so the compiler will complain when you try to pass it to the getDrawer method - but when you get into getDrawer, you don't use any existing value anyway! And you are trying to convert to a 16 bit integer, and return a 32 - this isn't a major problem, but just use int throughout.

So...try this:
C#
public class DesksP
{
    int Main()
    {
        int drawerA = getDrawer();
        Console.WriteLine("The number of drawers is/ are:{0}", drawerA);
    }

    private static int getDrawer()
    {
        Console.WriteLine("Enter number of drawers: ");
        return Convert.ToInt32((Console.ReadLine()));
    }

}
Though I would suggest that you might be better off looking at int.TryParse[^] to do the conversion, as it allows you to check if the user typed "Hello" instead of "107" and tell him off!
C#
int value;
Console.WriteLine("Enter number of drawers: ");
while (!int.TryParse(Console.ReadLine(), out value))
   {
   Console.WriteLine("Please enter a number!");
   }
return value;

GeneralRe: Passing a value from a method to the Main() Pin
Member 982953625-Nov-13 6:48
Member 982953625-Nov-13 6:48 
GeneralRe: Passing a value from a method to the Main() Pin
Ravi Bhavnani25-Nov-13 6:56
professionalRavi Bhavnani25-Nov-13 6:56 
GeneralRe: Passing a value from a method to the Main() Pin
OriginalGriff25-Nov-13 8:00
mveOriginalGriff25-Nov-13 8:00 
QuestionSpeechlib Pin
wernlin25-Nov-13 3:40
wernlin25-Nov-13 3:40 
AnswerRe: Speechlib Pin
Dave Kreskowiak25-Nov-13 4:40
mveDave Kreskowiak25-Nov-13 4:40 
GeneralRe: Speechlib Pin
wernlin25-Nov-13 5:03
wernlin25-Nov-13 5:03 
GeneralRe: Speechlib Pin
Dave Kreskowiak25-Nov-13 9:27
mveDave Kreskowiak25-Nov-13 9:27 
GeneralRe: Speechlib Pin
wernlin25-Nov-13 20:57
wernlin25-Nov-13 20:57 
GeneralRe: Speechlib Pin
Dave Kreskowiak26-Nov-13 1:21
mveDave Kreskowiak26-Nov-13 1:21 
GeneralRe: Speechlib Pin
wernlin26-Nov-13 1:39
wernlin26-Nov-13 1:39 
GeneralRe: Speechlib Pin
Dave Kreskowiak26-Nov-13 4:13
mveDave Kreskowiak26-Nov-13 4:13 
GeneralRe: Speechlib Pin
wernlin27-Nov-13 5:30
wernlin27-Nov-13 5:30 
Questionchange text from form Pin
messages25-Nov-13 3:33
messages25-Nov-13 3:33 
AnswerRe: change text from form Pin
Richard MacCutchan25-Nov-13 4:54
mveRichard MacCutchan25-Nov-13 4:54 
GeneralRe: change text from form Pin
messages25-Nov-13 5:20
messages25-Nov-13 5:20 
GeneralRe: change text from form Pin
Richard MacCutchan25-Nov-13 5:39
mveRichard MacCutchan25-Nov-13 5:39 
GeneralRe: change text from form Pin
messages25-Nov-13 5:50
messages25-Nov-13 5:50 

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.