靜態類別的建構式與方法執行先後
設定3個中斷點:
1. int gj() 的 return 1;
2. static internal int gi() 的 return 2;
3. static ttt() 的 aaa = 3;
測試後發現,先停在1,繼續執行後停在3,再繼續執行後停在2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int k = gj();
int j = ttt.gi();
int i = ttt.aaa;
}
int gj()
{
return 1;
}
}
static internal class ttt
{
internal static int aaa { get; set; }
static internal int gi()
{
return 2;
}
static ttt()
{
aaa = 3;
}
}
}