结构函数

   通过把结构体内部固定数据或固定代码结构化成一个函数,然后通过函数去调用更加方便。

   结构和枚举都是一种类型,结构和枚举都需要写在名称空间内部,原有的类外部!

  

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 结构函数
 7 {
 8     struct CustmerName
 9     {
10         public string firstName;
11         public string lastName;
12         public string GetName()
13         {
14             return firstName+""+lastName;
15         }
16     }
17 
18     class Program
19     {
20         static void Main(string[] args)
21         {
22             CustmerName MyName;
23             MyName.firstName = "";
24             MyName.lastName = "";
25 
26             //Console.WriteLine("我的名字:"+MyName.firstName+" "+MyName.lastName);
27             Console.WriteLine("My name is "+MyName.GetName());
28             Console.ReadKey();
29         }
30     }
31 }
原文地址:https://www.cnblogs.com/jc-1997/p/6071094.html