eiman13562
Member
- Joined
- Aug 1, 2021
- Messages
- 5
- Programming Experience
- Beginner
Program.cs :
Person.cs :
Iman Pour Soltani From Iran
Thank You For use
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Person_Class_Practice
{
class Program
{
static void Main(string[] args)
{
try
{
// برنامه پرسنل دوباره با استفاده از کلاس ها بازنگری شده
// Personnel schedule revised using classes
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Welcome to Person App V2");
Console.WriteLine(".");
Console.WriteLine(".");
Console.WriteLine(".");
Console.WriteLine(".");
Console.WriteLine(".");
Console.WriteLine(".");
Console.WriteLine(".");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("How many Create Person ?");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkYellow;
int CountPerson = Convert.ToInt32(Console.ReadLine());
Console.ResetColor();
Person[] Peoples = new Person[CountPerson]; // ساخت شئی جدید بصورت آرایه
// Build a new object as an array
for (int i = 0; i < CountPerson; i++)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Please enter Person Name [{(i + 1)}] : "); // بهتره حلقه عدد صفر را چاپ نکند پس با یک هر بار جمع شده
// It is better not to print the circle of zero, so it is added together one at a time
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkBlue;
string name = Console.ReadLine();
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Please enter Person family [{(i + 1)}] : ");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkBlue;
string family = Console.ReadLine();
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Please enter Person Age [{(i + 1)}] : ");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkBlue;
int age = Convert.ToInt32(Console.ReadLine());
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Please enter Person City [{(i + 1)}] : ");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkBlue;
string city = Console.ReadLine();
Console.ResetColor();
Person p = new Person(name, family, age, city); // ساخت شئی داخل حلقه
// Build the object inside the ring
Peoples[i] = p; // مقدار دهی شئی آرایه با شئی داخل حلقه
// Value the array object with the object inside the loop
}
foreach (Person person in Peoples)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"FullName : {person.name} {person.family} Age : {person.age} City : {person.city} ");
Console.ResetColor();
}
Console.ReadKey();
}
catch(FormatException)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Warning : Just only enter Number.");
Console.ResetColor();
Console.ReadKey();
}
catch
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Warning : Unknown error.");
Console.ResetColor();
Console.ReadKey();
}
}
}
Person.cs :
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Person_Class_Practice
{
class Person
{
public string name;
public string family;
public int age;
public string city;
public Person ( string name , string family,int age,string city)
{
this.name = name;
this.family = family;
this.age = age;
this.city = city;
}
}
}
Iman Pour Soltani From Iran
Thank You For use
Last edited by a moderator: