1、外部方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; //添加外部类库
namespace 外部方法
{
class Program
{
[DllImport("User32.dll")] //引用外部文件
public static extern int MessageBox(int h, string m, string c, int type);
static int Main(string[] args)
{
Console.Title = "外部方法";
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Red;
Console.Clear();
string userName;
Console.Write("请输入用户名:");
userName = Console.ReadLine();
Console.WriteLine();
MessageBox(0, userName + "用户,您好!", "消息框", 0);
return 0;
}
}
}
2、分部类分部方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 分部类分部方法
{
public partial class Student
{
private string studentID;
private string studentName;
public Student(string id,string name)
{
studentID = id;
studentName = name;
this.oncreate();
}
public void ShowMsg()
{
Console.WriteLine("学号:{0};姓名:{1}\n", studentID, studentName);
}
partial void oncreate();
}
class Program
{
static void Main(string[] args)
{
Console.Title = "分部类分部方法!!";
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
string id;
string name;
Console.Write("输入学号:");
id = Console.ReadLine();
Console.Write("输入姓名:");
name = Console.ReadLine();
Student Myobject = new Student(id,name);
Myobject.ShowMsg();
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 分部类分部方法
{
public partial class Student
{
partial void oncreate()
{
Console.WriteLine("Student类实例创建成功!\n");
}
}
}