I have list of objects and when I loop thought it and I want to print things into console. There is just same Author name in every object. When I go with breakpoints slowly throught every line It will print alright. I don't see logic why this happens. I have tried restarting visual studio etc. Nothing helped. Maybe is problem with that random generation? I don't know where then
Picture of how it is with breakpoints and without
CODE:
class Sentences
{
private int id;
private string sentence;
private string author;
public Sentences(int ID, string Sentence, string Author)
{
this.id = ID;
this.sentence = Sentence;
this.author = Author;
}
public int ID
{
get { return id; }
set { id = value; }
}
public string Sentence
{
get { return sentence; }
set { sentence = value; }
}
public string Author
{
get { return author; }
set { author = value; }
}
}
Main console app:
class Program
{
static void Main(string[] args)
{
List<Sentences> Sentences_list = new List<Sentences>();
string sentences = DownloadString("http://mvi.mechatronika.cool/sites/default/files/berces.html");
string[] partsFromString = sentences.Split(new string[] { @"." }, StringSplitOptions.None);
for(int i = 0 ; i < partsFromString.Length - 1 ; i++)
{
Sentences_list.Add(new Sentences(i+1,partsFromString[i],RandomString()));
}
var d = Sentences_list;
while (true)
{
string selected_from_menu = Menu();
if (selected_from_menu == "1")
{
Console.Clear();
foreach (Sentences s in Sentences_list)
{
Console.WriteLine("Autor: " + s.Author);
Console.WriteLine("ID: " + s.ID);
Console.WriteLine("Věta: " + s.Sentence);
Console.WriteLine("--------------------------------------------------");
Console.ReadLine();
}
}
}
}
public static string Menu()
{
Console.WriteLine("1 - Výpis všetkých záznamov");
Console.WriteLine("2 - Zmazanie záznamu podľa výberu užívateľa");
Console.WriteLine("3 - Editovanie záznamu a autora vety podľa v´beru užívateľa");
Console.WriteLine("4 - Pridanie záznamov");
Console.Write("Vyberte možnost: ");
string selected = Console.ReadLine();
return selected;
}
public static string RandomString()
{
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var stringChars = new char[4];
Random random = new Random();
for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)];
}
return new String(stringChars);
}
}