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

C#

 
QuestionProblem with BackgroundWorker component? Pin
Member 140558797-Apr-22 1:23
Member 140558797-Apr-22 1:23 
AnswerRe: Problem with BackgroundWorker component? Pin
Richard MacCutchan7-Apr-22 1:41
mveRichard MacCutchan7-Apr-22 1:41 
AnswerRe: Problem with BackgroundWorker component? Pin
Luc Pattyn7-Apr-22 6:30
sitebuilderLuc Pattyn7-Apr-22 6:30 
AnswerRe: Problem with BackgroundWorker component? Pin
Gerry Schmitz7-Apr-22 6:30
mveGerry Schmitz7-Apr-22 6:30 
QuestionC# Exception: An object reference does not point to an instance of an objec Pin
Member 155831391-Apr-22 0:29
Member 155831391-Apr-22 0:29 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Richard Deeming1-Apr-22 0:51
mveRichard Deeming1-Apr-22 0:51 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
OriginalGriff1-Apr-22 0:53
mveOriginalGriff1-Apr-22 0:53 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Richard MacCutchan1-Apr-22 1:07
mveRichard MacCutchan1-Apr-22 1:07 
GeneralRe: C# Exception: An object reference does not point to an instance of an objec Pin
Dave Kreskowiak1-Apr-22 2:12
mveDave Kreskowiak1-Apr-22 2:12 
GeneralRe: C# Exception: An object reference does not point to an instance of an objec Pin
Gary R. Wheeler2-Apr-22 3:21
Gary R. Wheeler2-Apr-22 3:21 
GeneralRe: C# Exception: An object reference does not point to an instance of an objec Pin
Pete O'Hanlon5-Apr-22 4:03
mvePete O'Hanlon5-Apr-22 4:03 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Raphael Adeniji10-Apr-22 14:20
Raphael Adeniji10-Apr-22 14:20 
AnswerRe: C# Exception: An object reference does not point to an instance of an objec Pin
Raphael Adeniji12-Apr-22 3:36
Raphael Adeniji12-Apr-22 3:36 
QuestionAccess Android Tablet from C# Pin
Kevin Marois30-Mar-22 18:23
professionalKevin Marois30-Mar-22 18:23 
AnswerRe: Access Android Tablet from C# Pin
Richard MacCutchan30-Mar-22 22:30
mveRichard MacCutchan30-Mar-22 22:30 
GeneralRe: Access Android Tablet from C# Pin
Kevin Marois31-Mar-22 6:15
professionalKevin Marois31-Mar-22 6:15 
GeneralRe: Access Android Tablet from C# Pin
Richard MacCutchan31-Mar-22 6:19
mveRichard MacCutchan31-Mar-22 6:19 
AnswerRe: Access Android Tablet from C# Pin
OriginalGriff31-Mar-22 3:09
mveOriginalGriff31-Mar-22 3:09 
GeneralRe: Access Android Tablet from C# Pin
Kevin Marois31-Mar-22 6:16
professionalKevin Marois31-Mar-22 6:16 
GeneralRe: Access Android Tablet from C# Pin
Kevin Marois31-Mar-22 8:11
professionalKevin Marois31-Mar-22 8:11 
GeneralRe: Access Android Tablet from C# Pin
OriginalGriff31-Mar-22 19:49
mveOriginalGriff31-Mar-22 19:49 
QuestionError when parsing string as int Pin
Member 1558328029-Mar-22 5:19
Member 1558328029-Mar-22 5:19 
Hi all,

I am receiving errors when executing below code.
The code asks me how many items the array has, and then let me fill the array with input.
The problem is whenever I input letters instead of numers I get an exception.
System.FormatException: 'Input string was not in a correct format.

The error happens at the following lines
C#
int size = Convert.ToInt32(Console.ReadLine());

&
C#
array[i] = Convert.ToInt32(Console.ReadLine());


Now I know that I might be using the int.TryParse method, by I do not know how to implement it.
Of perhaps when the input is not valid, give an error like
C#
Console.Write("Wrong input, only numbers");


My code:
C#
//Ask how many array items need to be present
Console.Write("How many items in the array ");
int size = Convert.ToInt32(Console.ReadLine());
int[] array = new int[size];

//Enter array items
Console.WriteLine("Enter {0} array items", size);
for (int i = 0; i < size; i++)
{
    array[i] = Convert.ToInt32(Console.ReadLine());
}

// Print array items
Console.Write("\nThe following items are in the array: ");
for (int i = 0; i < size; i++)
{
    Console.Write("{0} ", array[i]);
}
Console.ReadLine();


AnswerRe: Error when parsing string as int Pin
Dave Kreskowiak29-Mar-22 5:33
mveDave Kreskowiak29-Mar-22 5:33 
QuestionFind the smallest integer that is not in a random array Pin
Member 1204230226-Mar-22 8:01
Member 1204230226-Mar-22 8:01 
AnswerRe: Find the smallest integer that is not in a random array Pin
OriginalGriff26-Mar-22 8:22
mveOriginalGriff26-Mar-22 8:22 

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.