Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>Lesson3_封装_成员方法练习</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,66 @@
|
||||
namespace Lesson3_封装_成员方法练习
|
||||
{
|
||||
enum E_Occupation
|
||||
{
|
||||
Student = 0,
|
||||
Teacher = 1,
|
||||
}
|
||||
class Person
|
||||
{
|
||||
public string name;
|
||||
public string age;
|
||||
|
||||
|
||||
public void Speak(string str)
|
||||
{
|
||||
Console.WriteLine("{0}说了{1}", name, str);
|
||||
}
|
||||
public void Walk()
|
||||
{
|
||||
Console.WriteLine("{0}走了路", name);
|
||||
}
|
||||
public void Eat(Food food)
|
||||
{
|
||||
Console.WriteLine("{0}吃了{1},共计{2}卡路里", name, food.name, food.Calorie);
|
||||
}
|
||||
}
|
||||
class Student
|
||||
{
|
||||
public string name;
|
||||
public void Study()
|
||||
{
|
||||
Console.WriteLine("{0}学了习", name);
|
||||
}
|
||||
public void Eat(Food food)
|
||||
{
|
||||
Console.WriteLine("{0}吃了{1},共计{2}卡路里", name, food.name, food.Calorie);
|
||||
}
|
||||
}
|
||||
class Food
|
||||
{
|
||||
public string name;
|
||||
public int Calorie;
|
||||
|
||||
}
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Person p = new Person();
|
||||
p.name = "Test";
|
||||
p.Speak("hello");
|
||||
p.Walk();
|
||||
//p.Eat();
|
||||
Student s = new Student();
|
||||
s.name = "Test2";
|
||||
s.Study();
|
||||
//s.Eat();
|
||||
|
||||
Food bread = new Food();
|
||||
bread.name = "Bread";
|
||||
bread.Calorie = 200;
|
||||
s.Eat(bread);
|
||||
p.Eat(bread);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user