I was recently trying to learn C # and I found this problem. - Create a class called person with some attributes. What I want to do is save all the "people" that the user loads the system into a list to then do things with this information, but when I try to go through this list to show all the people loaded the only thing that throws the system is as follows : "the namespace of the project" .Person
Here is the code
using System;
using System.Collections.Generic;
namespace Clases_csharp
{
class Program
{
public static void Main(string[] args)
{
Person.Carga_Persona();
Console.WriteLine("Total:" + Person.count);
Console.ReadKey();
}
}
class Person
{
public static int count;
public string date_of_birth;
public string name,lastname;
public string obs;
public double CIndex;
public Person (string _date_Of_birth,string _name,string _lastname,string _Obs,double _CIndex)
{
date_of_birth = _date_Of_birth;
name = _name;
lastname = _lastname;
obs = _Obs;
CIndex = _CIndex;
}
public static void Carga_Persona ()
{
List<Person> todos = new List<Person>();
Console.WriteLine("enter 1 to register a new person, 2 to stop");
int des = Convert.ToInt32(Console.ReadLine());
while (des ==1)
{
Console.WriteLine("Enter the Date of birth of the person");
string date = Console.ReadLine();
Console.WriteLine("Enter the name");
string name = Console.ReadLine();
Console.WriteLine("Enter the Last Name");
string Last_Name = Console.ReadLine();
Console.WriteLine("Enter the Observations about de person");
string obs = Console.ReadLine();
Console.WriteLine("Enter the Index");
double Index = Convert.ToDouble(Console.ReadLine());
Person person1 = new Person(date,name,Last_Name,obs,Index);
count += 1 ;
todos.Add(person1);
Console.WriteLine("enter 1 to register a new person, 2 to stop");
des = Convert.ToInt32(Console.ReadLine());
}
int large = todos.Count ;
for (int i = 0; i < large; i++) {
Console.WriteLine(todos[i]);
}
}
}
}
When I run the debugger all the variables seem to have the correct values and the list has saved all the "People" that it loads.
Thank you!