#C# error handling

12 messages · Page 1 of 1 (latest)

rigid cedar
#

For my uni work im doing error handling and currnetly trying to do a ArgumentOutOfRangeException. with the code below as the main part. when i run it i get an error saying 'List<int>' does not contain a constructor that takes 3 arguments and i dont know what i need to do to fix it. i am intentionally trying to get the exception.

try
{
List<int> lst = new List<int>( 100, 200, 300 );
Console.WriteLine(lst[3]); // Throws ArgumentOutOfRangeException
Console.ReadLine();
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine("ArgumentOutOfRangeException: " + ex.Message);
}

empty finch
rigid cedar
#

sure, im finding it ok with the actual assignment just when i try and run the code it doesnt even start

tiny pythonBOT
#

@rigid cedar

File Attachments Not Allowed

For safety reasons we do not allow files with certain file extensions.

Code Formatting

You can share your code using triple backticks like this:
```
YOUR CODE
```

Large Portions of Code

For longer scripts use Hastebin or GitHub Gists and share the link here

Ignored these files due to them having disallowed file extensions
  • 994d18e6-89e5-4662-b763-21f917673b4e.pdf
empty finch
#

pdf won't work. You will probably have to send a screenshot

rigid cedar
#

ok

#

ive already done most of it i just need to fix up a couple parts and this was one of them

empty finch
#

Ok I think you get an error because the way you are creating lst is wrong

#

List<int> lst = new List<int>(){100, 200, 300}; try this?

#

I haven't written C# so I am not sure if it will work

rigid cedar
#

that worked