Foreach Problem || List || NullReferenceException: Object reference not set to an instance of an object

I am creating a load mechanicism and where it says “foreach(string str in Segment)” returns the error: "NullReferenceException: Object reference not set to an instance of an object
Variables.Load (Int32 Number) (at Assets/Scripts/Variables.cs:65)
Variables.Start () (at Assets/Scripts/Variables.cs:13)
"

public void Load(int Number)
{
string text = System.IO.File.ReadAllText(@“” + Number + “Save.txt”);
char characters = text.ToCharArray();
bool Write = false;
bool First = false;
List Segment = null;
string TempSegment = “”;
for (int i = 0; i <= characters.Length - 1; i++)
{

            if (characters *== ('n') && characters[i-1] == '\\')*

{
if (First)
{
Segment.Add(TempSegment);
}
else
{
First = true;
}

Write = true;
}
else if (characters == (‘\’))
{

}
else
{
TempSegment += characters*;*
}
}

foreach(string str in Segment)
{
string TempDataType = “”, TempName = “”, TempValue = “”, TempUUID = “”;
int turn = 0;
char[] part = str.ToCharArray();
for (int i = 0; i <= str.Length - 1; i++)
{

if (part == (‘a’) && part[i - 1] == ‘\’)
{
turn++;
}
else if (part == (‘\’))
{

}
else
{
switch (turn)
{
case 0:
TempDataType += str*;*
break;
case 1:
TempName += str*;*
break;
case 2:
TempValue += str*;*
break;
case 3:
TempUUID += str*;*
break;

}

}
}
VariableSave save = null;
save.DataType = TempDataType;
save.Name = TempName;
save.Value = TempValue;
save.UUID = TempUUID;
VariableLoad.Add(save);
}

}
I do not know why this error happens, so if you can explain that would be awesome. This might be becuase foreach is not compatible with List

It says in your code for the Load method that List Segment = null; but then you never create a list called segment anywhere after that shouldn’t it read List<Segment> segment = new List<Segment>(); assuming you are using c# of course. But the question is poorly formatted so hard to tell.