Advertisement
NS2A2

Bài 1 C#

Dec 20th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Test
  8. {
  9.     class Person
  10.     {
  11.         private string _name;
  12.         private int _age;
  13.         private string _hobby;
  14.         private string _sex;
  15.  
  16.         public string Name { get; set; }
  17.         public int Age { get; set; }
  18.         public string Hobby { get; set; }
  19.         public string Sex { get; set; }
  20.  
  21.         public Person(string name, int age, string hobby, string sex)
  22.         {
  23.             Name = name;
  24.             Age = age;
  25.             Hobby = hobby;
  26.             Sex = sex;
  27.         }
  28.  
  29.         public void Cout()
  30.         {
  31.             Console.WriteLine("Name = {0}, Age = {1}, Hobby = {2}, Sex = {3}",Name,Age,Hobby,Sex);
  32.         }
  33.     }
  34.     class RunMain
  35.     {
  36.         static void Main(string[] args)
  37.         {
  38.             Person SonNghien = new Person("Son",16,"haha","male");
  39.             Person TuBueDe = new Person("Tu",18,"hehe","female");
  40.             SonNghien.Cout();
  41.             TuBueDe.Cout();
  42.             Console.ReadKey();
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement