using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public struct Name
{
//字段
private string fName, mName, lName;
public Name(string fname, string mname, string lname)
{
fName = fname;
mName = mname;
lName = lname;
}
//属性
public string firstName
{
get { return fName; }
set { fName = value; }
}
public string middleName
{
get { return mName; }
set { mName = value; }
}
public string lastName
{
get { return lName; }
set { lName = value; }
}
//重写ToString()方法
public override string ToString()
{
return String.Format("{0} {1} {2}", fName, mName, lName);
}
public string Initials()
{
return (String.Format("{0}{1}{2}", fName.Substring(0, 1), mName.Substring(0, 1), lName.Substring(0, 1)));
}
}
class NameTest
{
static void Main()
{
Name myName = new Name("Michael", "Mason", "McMillan");
string fullName, initsName;
fullName = myName.ToString();
initsName = myName.Initials();
Console.WriteLine(fullName);
Console.WriteLine(initsName);
Console.Read();
}
}
}
运行结果:
Michael Mason McMillan
MMM
网友评论