110,539
社区成员
发帖
与我相关
我的任务
分享
using System.Collections.Generic;
namespace ConsoleApp1
{
public class 百家祖谱库
{
public static string 姓氏 = string.Empty;
public 百家祖谱库(string XS)
{
百家祖谱库.姓氏 = XS;
}
public static string Get第N代祖先(int N)
{
//实际是连接数据库,从库里获取祖先List
List<string> 祖先List = new List<string>();
祖先List.Add("龙");
祖先List.Add("腾");
祖先List.Add("四");
祖先List.Add("海");
祖先List.Add("云");
祖先List.Add("鹤");
祖先List.Add("九");
祖先List.Add("霄");
return 祖先List[N - 1];
}
}
public class 李家祖谱Manager:百家祖谱库
{
//试探写法一
//public 李家祖谱Manager()
//{
// MyBaseClass.姓氏 = "李";
//}
//试探写法二
public 李家祖谱Manager()
:base("李")
{
百家祖谱库.姓氏 = "李";
}
//试探写法三
public 李家祖谱Manager("李")
: base()
{
百家祖谱库.姓氏 = "李";
}
}
public class 王家祖谱Manager
{
//根据李家一样
}
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("李家第3代祖先是:"李家祖谱Manager.Get第N代祖先(3));
}
}
}
/// <summary>
/// 百家姓
/// </summary>
public class ChineseSurnames
{
/// <summary>
/// 姓氏
/// </summary>
public string FamilyName { get; set; }
private List<string> ancestor = new List<string>();
/// <summary>
/// 祖先名
/// </summary>
public List<string> Ancestor { get {
if (ancestor==null || ancestor.Count()==0)
{
ancestor.Add("龙");
ancestor.Add("腾");
ancestor.Add("四");
ancestor.Add("海");
ancestor.Add("云");
ancestor.Add("鹤");
ancestor.Add("九");
ancestor.Add("霄");
}
return ancestor;
} }
/// <summary>
///
/// </summary>
/// <param name="familyName">姓氏</param>
public ChineseSurnames(string familyName)
{
this.FamilyName = familyName;
}
/// <summary>
/// 获取第N代祖先名字
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
public virtual string GetAncestor(int num)
{
string msg = FamilyName + "家族谱第" + num + "代祖先名字" + FamilyName + Ancestor[num - 1];
return msg;
}
}
/// <summary>
/// 【李】家姓氏
/// </summary>
public class LiFamilyTree : ChineseSurnames
{
public LiFamilyTree(string familyName) : base(familyName)
{
}
}
class Program
{
static void Main(string[] args)
{
ChineseSurnames li = new LiFamilyTree("李");
Console.WriteLine(li.GetAncestor(2));
Console.ReadKey();
}
}
using System.Collections.Generic;
namespace ConsoleApp1
{
public class 百家祖谱库
{
public static string 姓氏 = string.Empty;
public 百家祖谱库(string XS)
{
百家祖谱库.姓氏 = XS;
}
public static string Get第N代祖先(int N)
{
//实际是连接数据库,从库里获取祖先List
List<string> 祖先List = new List<string>();
祖先List.Add("龙");
祖先List.Add("腾");
祖先List.Add("四");
祖先List.Add("海");
祖先List.Add("云");
祖先List.Add("鹤");
祖先List.Add("九");
祖先List.Add("霄");
//每次到这处,姓氏总为空
return 姓氏+祖先List[N - 1];
}
}
public class 李家祖谱Manager:百家祖谱库
{
//试探写法一
//public 李家祖谱Manager()
//{
// MyBaseClass.姓氏 = "李";
//}
//试探写法二
public 李家祖谱Manager()
:base("李")
{
百家祖谱库.姓氏 = "李";
}
//试探写法三
public 李家祖谱Manager("李")
: base()
{
百家祖谱库.姓氏 = "李";
}
}
public class 王家祖谱Manager
{
//根据李家一样
}
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("李家第3代祖先是:"李家祖谱Manager.Get第N代祖先(3));
}
}
}