Synchronization of old projects

Part1
This commit is contained in:
2025-09-30 16:46:01 +08:00
parent 116b65164b
commit 4e1548abe2
167 changed files with 8668 additions and 43 deletions
@@ -0,0 +1,130 @@
namespace Lesson6
{
internal class Program
{
#region
class
{
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
}
#endregion
#region
//基本概念
//让对象可以像数组一样通过索引器访问其中元素,使程序看起来更只管,更容易编写
//(不用数组了)
#endregion
#region
//访问修饰符 返回值 this[参数类型 参数名,参数类型 参数名......]
//{
// 内部的写法可规则和索引器相同
// get{}
// set{}
//}
class Person
{
private string name;
private int age;
private Person[] friends;
private int[,] array;
#region
//重载的概念是————函数名相同 但 参数类型、数量、顺序不同
#endregion
public int this[int i, int j]
{
get
{
return array[i, j];
}
set
{
array[i, j] = value;
}
}
public string this[string str]
{
get
{
switch (str)
{
case "name":
return this.name;
case "age":
return this.age.ToString();
default:
return "";
}
}
set
{
this[str] = value;
}
}
public Person this[int index]
{
get
{
#region
#endregion
if (friends == null)
{
return null;
}
else if (friends.Length - 1 < index)
{
return null;
}
else
{
return friends[index];
}
}
set
{
if (friends == null)
{
friends = new Person[] { value };
}else if(index > friends.Length -1)
{
friends = new Person[] { value };
}
}
}
}
#endregion
#region
#endregion
#region
#endregion
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
#region
Person p = new Person();
p[0] = new Person();
Console.WriteLine(p[0]);
p[0, 0] = 10;
#endregion
}
}
}