图解C#教程 《Illustrated C# 7.0 The C# Language Presented Clearly,Concisely, and Visually Fifth Edition》
Stack Frames
栈帧
其实我至今为止对计算机很多魔幻翻译不理解。这个帧frame,算是一例。我有限的知识理解成 一层两层,包裹起来的,类似花括号区分开来的block区块一样,只是这个block是在内存stack上操作进行的。
So far, you know that local variables and parameters are kept on the stack. In this section, we'll look at that
organization a bit further.
到目前为止,你已经知道本地变量local variables 和 参数 parameters 是被保存在栈中 stack。
When a method is called, memory is allocated at the top of the stack to hold a number of data items associated with the method. This chunk of memory is called the stack frame for the method.
当一个方法method(也即函数)被call的时候,在栈顶端,分配一段内存,保存和方法关联的一些数据项a number of data items 。
这一块内存叫做方法的stack frame
• The stack frame contains memory to hold the following:
栈帧包含返回地址---也就是方法退出的时候继续执行的位置。
– The return address—that is, where to resume execution when the method exits
分配了内存的参数---也就是方法的值参数,还可能是数组参数(如果有的话)
– Those parameters that allocate memory—that is, the value parameters of the method, and the parameter array if there is one
和方法调用相关的其他管理数据线项。
– Various other administrative data items relevant to the method call
• When a method is called, its entire stack frame is pushed onto the stack.
当一个方法被调用的时候,call,整个栈帧被压入栈
• When the method exits, its entire stack frame is popped from the stack. Popping a stack frame is sometimes called unwinding the stack
当一个方法结束(exits),整个栈帧被弹出。弹出栈帧有的时候也叫做栈展开,unwinding
静态字段
Static Fields 是相对于 实例字段 而言的 Besides instance fields, classes can have what are called static fields.
Instance Fields 实例字段
实例字段 是需要实例化的。反过来,static一下 就是拿来可以用的意思
using System;
class X
{
static public int A; // Static field
static public void PrintValA() // Static method
{
Console.WriteLine( "Value of A: {0}", A );
}
}
class Program
{
static void Main()
{
X.A = 10; // Use dot-syntax notation
X.PrintValA(); // Use dot-syntax notation
}
}
拿来就可以用。本人比较熟悉vb,所以vba的那种感觉来了。