c#


C# - I get the following error when I add a number while running my program 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll" [duplicate]


This question already has an answer here:
What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?
2 answers
So im trying to fill the courses on my program and when I click the Input button instead of proceeding to the next student I get this error "An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll"
Here is the button
namespace WpfApplication1{
public partial class MainWindow : Window {
List<Students> student = new List<Students>();
int positionIndex = 0;
public MainWindow() {
InitializeComponent();
}
void btnExe_Click(object sender, RoutedEventArgs e) {
var course1 = Convert.ToDouble(txtCourse1.Text);
var course2 = Convert.ToDouble(txtCourse2.Text);
var course3 = Convert.ToDouble(txtCourse3.Text);
student[positionIndex].c1 = course1;
student[positionIndex].c2 = course2;
student[positionIndex].c3 = course3;
student[positionIndex].Name = positionIndex;
stdNames.Text = student[positionIndex].Name.ToString();
positionIndex++;
if (positionIndex == 6) {
btnExe.IsEnabled = false;
calculate();
};
}
Here is the class
namespace WpfApplication1 {
public class Students {
public int Name { get; set; }
public double c1 { get ; set; }
public double c2 { get; set; }
public double c3 { get; set; }
}
}
Thanks in advance, I really can't figoure out what is wrong.
Create an instance before accessing the item. student.Add(new Students());
void btnExe_Click(object sender, RoutedEventArgs e) {
var course1 = Convert.ToDouble(txtCourse1.Text);
var course2 = Convert.ToDouble(txtCourse2.Text);
var course3 = Convert.ToDouble(txtCourse3.Text);
student.Add(new Students());
student[positionIndex].c1 = course1;
student[positionIndex].c2 = course2;
student[positionIndex].c3 = course3;
student[positionIndex].Name = positionIndex;
stdNames.Text = student[positionIndex].Name.ToString();
positionIndex++;
if (positionIndex == 6) {
btnExe.IsEnabled = false;
calculate();
};
}

Related Links

How to deal with DBNull in DataContractSerializer?
Inheritance Variable Questions (Changing inherited variables) in Unity (C#)
Unable to update main form control from subclass
On an ASP.NET HTML page with a DO/WHILE loop: How to stop then continue loop with SUBMIT button
How to have events separated at least by a given time span?
Getting error in Unity Universal Windows Platform
Can a non-nullable int be null? [duplicate]
Delete from one, add to another Listbox and vice versa with the same sorting like before
use unrar.dll in a c# project to retrieve the list of file and relative CRC code
How to declare an array containing generic type?
Manage multiple authentications with ASP.NET Identity
Is there any reason to keep a settings file nested underneath properties?
IIS Web Application can't be accessed remotely
re-number a value by 1 if same value
Fix error with route url in Asp.Net MVC 5
Calling AWS Lambda Fucntion from MVC controller

Categories

HOME
oop
botframework
gsm
ebay-api
livecharts
okhttp3
bitbucket
crash
travis-ci-cli
runtime
core-data
drush
yui
appsettings
project-structure
ampscript
gomobile
javaagents
smali
advertising
policy
sha
deployment-descriptor
orgchart
uibarbuttonitem
andengine
qt-designer
snapkit
azure-vm-scale-set
android-databinding
rythm
console.readline
anypoint-studio
jibx
area
file-descriptor
google-cloud-powershell
aspnetboilerplate
quartz
text-extraction
nshttpurlresponse
risc
noise
dynamic-linking
activesupport
sharpssh
computed-properties
optional-parameters
papyrus
xcode7.1
syslog4j
python-rq
archiva
camellia
methodology
jersey-test-framework
encode
android-facebook
ruby-1.8.7
redquerybuilder
log4cxx
pushwoosh
borland-c++
vensim
p4python
mergecursor
accpac
pysvn
illegalargumentexception
go-gin
vundle
dirname
worklight-appcenter
ios-enterprise
dotcmis
fscanf
drawable
isl
starling-framework
nativequery
maven-javadoc-plugin
grunt-wiredep
aspnet-compiler
static-class
nokogiri
playing-cards
removeall
spawn
screensharing
gssapi
junit-rule
doxia
copyfile
utm
umfpack
zipstream
n2
cpack
stackless

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App