TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jamie Dalley
NA
16
5.7k
What is wrong with this method / method call?
Jan 30 2013 7:09 AM
Basically i need to make a method that switches the value of two numbers. For some reason at the moment when my program gets to this part it comes up with an error saying input string was not in a correct format. Below i have pasted the bit of the code with the method and the call, any help would be great, thanks in advance:
int originalNumber;
int switchNumber;
Console.WriteLine("Enter a number");
originalNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("You entered {0}, please enter a second number for it to be switched with", originalNumber);
switchNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The first number is {0} and the second is {1}, press any key to switch them", originalNumber, switchNumber);
Console.ReadKey();
SwapNumbers(originalNumber, switchNumber);
Console.WriteLine("The first number is now {0} and the second is now {1)", originalNumber, switchNumber);
Console.WriteLine("Press any key to end program");
Console.ReadKey();
}
public static void SwapNumbers(int firstNumber, int secondNumber)
{
int temp = 0;
temp = firstNumber;
firstNumber = secondNumber;
secondNumber = temp;
}
Reply
Answers (
6
)
Why doesn't this array work properly?
grid view cell validation