Om jag har en if sats som den nedan och sedan sätter variabeln till HomeTeamH1ResSer2, Om koden inte går in i if-satsen så kommer variabeln vara unassigned, därför får du det felet. Om du vet att den alltid kommer sättas kan du göra en fuling och deklarera variabeln såhär: Det kommer den att göra. varför inte bara byta ut Det går inte för jag har flera if satser sedan! Men det kanske finns smartare lösningar?Compiler Error Message: CS0165: Use of unassigned local variable
varför får jag då error :
Compiler Error Message: CS0165: Use of unassigned local variable 'HomeTeamH1ResSer2'
Source Error:
Line 374: }
Line 375:
Line 376: HomeTeamResSer2 = HomeTeamH1ResSer2;// +HomeTeamH2ResSer2 + HomeTeamH3ResSer2;// +HomeTeamH4ResSer2;
Line 377: LblHomeTeamResSer2.Text = HomeTeamResSer2.ToString();
Line 378:
int HomeTeamH1ResSer2;
int HomeTeamH2ResSer2;
int HomeTeamH3ResSer2;
int HomeTeamH4ResSer2;
if (m.H1ResSer2 != 0)
{
LblShirtNo1HResSer2.Text = m.H1ResSer2.ToString();
LblShirtNo1HSer2.Text = m.H1SpelarNamn;
HomeTeamH1ResSer2 = int.Parse(m.H1ResSer2.ToString()) + int.Parse(m.H2ResSer2.ToString());
LblHomeTeamH1ResSer2.Text = HomeTeamH1ResSer2.ToString();
}
else if (m.H1ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H1SpelarNamn;
LblShirtNo1HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo1HSer2.Text = m.H9SpelarNamn;
HomeTeamH1ResSer2 = int.Parse(m.H1ResSer2.ToString()) + int.Parse(m.H2ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH1ResSer2.Text = HomeTeamH1ResSer2.ToString();
}
if (m.H2ResSer2 != 0)
{
LblShirtNo2HResSer2.Text = m.H2ResSer2.ToString();
LblShirtNo2HSer2.Text = m.H2SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
else if (m.H2ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H2SpelarNamn;
LblShirtNo2HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo2HSer2.Text = m.H9SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H1ResSer2.ToString()) + int.Parse(m.H2ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
HomeTeamResSer2 = HomeTeamH1ResSer2;// +HomeTeamH2ResSer2 +
HomeTeamH3ResSer2 + HomeTeamH4ResSer2;
LblHomeTeamResSer2.Text = HomeTeamResSer2.ToString();
Sv: Compiler Error Message: CS0165: Use of unassigned local variable
int HomeTeamH1ResSer2 = 0;
/JohanSv:Compiler Error Message: CS0165: Use of unassigned local variable
TackSv: Compiler Error Message: CS0165: Use of unassigned local variable
else if (m.H1ResSer2 == 0)
mot
else
blir enklare att förstå för alla (inklusive kompilatorn)Sv:Compiler Error Message: CS0165: Use of unassigned local variable
#region Serie2 // Serie2
int HomeTeamH1ResSer2 = 0;
int HomeTeamH2ResSer2 = 0;
int HomeTeamH3ResSer2 = 0;
int HomeTeamH4ResSer2 = 0;
int AwayTeamB1ResSer2 = 0;
int AwayTeamB2ResSer2 = 0;
int AwayTeamB3ResSer2 = 0;
int AwayTeamB4ResSer2 = 0;
int HomeTeamResSer2 = 0 ;
int HomeTeamH9ResSer2;
string ReservHomeTeamSer2;
int AwayTeamResSer2 = 0;
int AwayTeamA9ResSer2;
string ReservAwayTeamSer2;
if (m.H1ResSer2 != 0)
{
LblShirtNo1HResSer2.Text = m.H1ResSer2.ToString();
LblShirtNo1HSer2.Text = m.H1SpelarNamn;
HomeTeamH1ResSer2 = int.Parse(m.H1ResSer2.ToString()) + int.Parse(m.H2ResSer2.ToString());
LblHomeTeamH1ResSer2.Text = HomeTeamH1ResSer2.ToString();
}
else if (m.H1ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H1SpelarNamn;
LblShirtNo1HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo1HSer2.Text = m.H9SpelarNamn;
HomeTeamH1ResSer2 = int.Parse(m.H1ResSer2.ToString()) + int.Parse(m.H2ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH1ResSer2.Text = HomeTeamH1ResSer2.ToString();
}
if (m.H2ResSer2 != 0)
{
LblShirtNo2HResSer2.Text = m.H2ResSer2.ToString();
LblShirtNo2HSer2.Text = m.H2SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
else if (m.H2ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H2SpelarNamn;
LblShirtNo2HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo2HSer2.Text = m.H9SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H1ResSer2.ToString()) + int.Parse(m.H2ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
if (m.H3ResSer2 != 0)
{
LblShirtNo3HResSer2.Text = m.H3ResSer2.ToString();
LblShirtNo3HSer2.Text = m.H3SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
else if (m.H3ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H3SpelarNamn;
LblShirtNo3HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo3HSer2.Text = m.H9SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString()) +int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
if (m.H4ResSer2 != 0)
{
LblShirtNo4HResSer2.Text = m.H4ResSer2.ToString();
LblShirtNo4HSer2.Text = m.H4SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
else if (m.H4ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H4SpelarNamn;
LblShirtNo4HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo4HSer2.Text = m.H9SpelarNamn;
HomeTeamH2ResSer2 = int.Parse(m.H3ResSer2.ToString()) + int.Parse(m.H4ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH2ResSer2.Text = HomeTeamH2ResSer2.ToString();
}
if (m.H5ResSer2 != 0)
{
LblShirtNo5HResSer2.Text = m.H5ResSer2.ToString();
LblShirtNo5HSer2.Text = m.H5SpelarNamn;
HomeTeamH3ResSer2 = int.Parse(m.H5ResSer2.ToString()) + int.Parse(m.H6ResSer2.ToString());
LblHomeTeamH3ResSer2.Text = HomeTeamH3ResSer2.ToString();
}
else if (m.H5ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H5SpelarNamn;
LblShirtNo5HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo5HSer2.Text = m.H9SpelarNamn;
HomeTeamH3ResSer2 = int.Parse(m.H5ResSer2.ToString()) + int.Parse(m.H6ResSer2.ToString()) +int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH3ResSer2.Text = HomeTeamH3ResSer2.ToString();
}
if (m.H6ResSer2 != 0)
{
LblShirtNo6HResSer2.Text = m.H6ResSer2.ToString();
LblShirtNo6HSer2.Text = m.H6SpelarNamn;
HomeTeamH3ResSer2 = int.Parse(m.H5ResSer2.ToString()) + int.Parse(m.H6ResSer2.ToString());
LblHomeTeamH3ResSer2.Text = HomeTeamH3ResSer2.ToString();
}
else if (m.H6ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H3SpelarNamn;
LblShirtNo6HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo6HSer2.Text = m.H9SpelarNamn;
HomeTeamH3ResSer2 = int.Parse(m.H5ResSer2.ToString()) + int.Parse(m.H6ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH3ResSer2.Text = HomeTeamH3ResSer2.ToString();
}
if (m.H7ResSer2 != 0)
{
LblShirtNo7HResSer2.Text = m.H7ResSer2.ToString();
LblShirtNo7HSer2.Text = m.H7SpelarNamn;
HomeTeamH4ResSer2 = int.Parse(m.H7ResSer2.ToString()) + int.Parse(m.H8ResSer2.ToString());
LblHomeTeamH4ResSer2.Text = HomeTeamH4ResSer2.ToString();
}
else if (m.H7ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H3SpelarNamn;
LblShirtNo7HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo7HSer2.Text = m.H9SpelarNamn;
HomeTeamH4ResSer2 = int.Parse(m.H7ResSer2.ToString()) + int.Parse(m.H8ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH4ResSer2.Text = HomeTeamH4ResSer2.ToString();
}
if (m.H8ResSer2 != 0)
{
LblShirtNo8HResSer2.Text = m.H8ResSer2.ToString();
LblShirtNo8HSer2.Text = m.H8SpelarNamn;
HomeTeamH4ResSer2 = int.Parse(m.H7ResSer2.ToString()) + int.Parse(m.H8ResSer2.ToString());
LblHomeTeamH4ResSer2.Text = HomeTeamH4ResSer2.ToString();
}
else if (m.H8ResSer2 == 0)
{
ReservHomeTeamSer2 = m.H8SpelarNamn;
LblShirtNo8HResSer2.Text = m.H9ResSer2.ToString();
LblShirtNo8HSer2.Text = m.H9SpelarNamn;
HomeTeamH4ResSer2 = int.Parse(m.H7ResSer2.ToString()) + int.Parse(m.H8ResSer2.ToString()) + int.Parse(m.H9ResSer2.ToString());
LblHomeTeamH4ResSer2.Text = HomeTeamH4ResSer2.ToString();
}
HomeTeamResSer2 = HomeTeamH1ResSer2 + HomeTeamH2ResSer2 + HomeTeamH3ResSer2 + HomeTeamH4ResSer2;
LblHomeTeamResSer2.Text = HomeTeamResSer2.ToString();
if (m.A1ResSer2 != 0)
{
LblShirtNo1ASer2.Text = m.A1SpelarNamn;
LblShirtNo1AResSer2.Text = m.A1ResSer2.ToString();
AwayTeamB1ResSer2 = int.Parse(m.A1ResSer2.ToString()) + int.Parse(m.A2ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
else if (m.A1ResSer2 == 0)
{
ReservAwayTeamSer2 = m.A1SpelarNamn;
LblShirtNo1AResSer2.Text = m.A9ResSer2.ToString();
LblShirtNo1ASer2.Text = m.A9SpelarNamn;
AwayTeamB1ResSer2 = int.Parse(m.A1ResSer2.ToString()) + int.Parse(m.A2ResSer2.ToString()) + int.Parse(m.A9ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
if (m.A2ResSer2 != 0)
{
LblShirtNo2ASer2.Text = m.A2SpelarNamn;
LblShirtNo2AResSer2.Text = m.A3ResSer2.ToString();
AwayTeamB1ResSer2 = int.Parse(m.A1ResSer2.ToString()) + int.Parse(m.A2ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
else if (m.A2ResSer2 == 0)
{
ReservAwayTeamSer2 = m.A2SpelarNamn;
LblShirtNo2AResSer2.Text = m.A9ResSer2.ToString();
LblShirtNo2ASer2.Text = m.A9SpelarNamn;
AwayTeamB1ResSer2 = int.Parse(m.A1ResSer2.ToString()) + int.Parse(m.A2ResSer2.ToString()) + int.Parse(m.A9ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
if (m.A3ResSer2 != 0)
{
LblShirtNo3AResSer2.Text = m.A3ResSer2.ToString();
LblShirtNo3ASer2.Text = m.A3SpelarNamn;
AwayTeamB2ResSer2 = int.Parse(m.A3ResSer2.ToString()) + int.Parse(m.A4ResSer2.ToString());
LblAwayTeamB2ResSer2.Text = AwayTeamB2ResSer2.ToString();
}
else if (m.A3ResSer2 == 0)
{
ReservAwayTeamSer2 = m.A3SpelarNamn;
LblShirtNo3AResSer2.Text = m.A9ResSer2.ToString();
LblShirtNo3ASer2.Text = m.A9SpelarNamn;
AwayTeamB1ResSer2 = int.Parse(m.A3ResSer2.ToString()) + int.Parse(m.A4ResSer2.ToString()) + int.Parse(m.A9ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
if (m.A4ResSer2 != 0)
{
LblShirtNo4AResSer2.Text = m.A4ResSer2.ToString();
LblShirtNo4ASer2.Text = m.A4SpelarNamn;
AwayTeamB1ResSer2 = int.Parse(m.A1ResSer2.ToString()) + int.Parse(m.A2ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
else if (m.A4ResSer2 == 0)
{
ReservAwayTeamSer2 = m.A2SpelarNamn;
LblShirtNo2AResSer2.Text = m.A9ResSer2.ToString();
LblShirtNo2ASer2.Text = m.A9SpelarNamn;
AwayTeamB1ResSer2 = int.Parse(m.A1ResSer2.ToString()) + int.Parse(m.A2ResSer2.ToString()) + int.Parse(m.A9ResSer2.ToString());
LblAwayTeamB1ResSer2.Text = AwayTeamB1ResSer2.ToString();
}
AwayTeamResSer2 = AwayTeamB1ResSer2 + AwayTeamB2ResSer2 + AwayTeamB3ResSer2 + AwayTeamB4ResSer2;
LblAwayTeamResSer2.Text = AwayTeamResSer2.ToString();
#endregion