Basic definition and description of 02-c# (Basic)

Source: Internet
Author: User

The source code of a C # program or DLL is a set of types of declarations

class : A type is a template that you can think of as a template for creating data structures. The template itself is not a data structure, but it details the characteristics of the objects that the template constructs.

Namespaces : It is a method of grouping and naming related types of declarations. Since a program is a set of related type declarations, it is common to declare programs within the namespace that is created.

For an executable program, a type declaration must contain a Main method .

Here's the. The predefined types in net:

Heap and Stack

For. NET platform, the concept of using stacks in memory to hold data.
A stack is an array of memory that is a LIFO (last-in first-out LIFO) data structure.
Data types stored in the stack: value type data, address of the reference type, program's current execution environment, parameters passed to the method.
The characteristics of the stack: data can only be inserted and deleted from the top of the stack, put the data on the top of the stack called the stack (push), from the top of the stack to delete data called the stack (POP), so you can think of the stack as a water cup.

Stack Frames

When a method is called, a block of memory is allocated at the top of the stack to hold data items related to the method, which is called the stack frame of the method.
The data stored in the stack frame are: The return address (where the method exits where execution continues), the parameters that allocate memory (that is, the value parameters of the method), and the various other management data items associated with the method invocation.
When the method is called, its entire stack frame is pressed into the stack, and when the method exits, its entire stack frame pops up from the stack. Popping a stack frame is sometimes called a release stack.

Heap

Unlike stacks, a heap is an area of memory in which chunks of memory can be allocated to store data of a certain type, and the memory in the heap can be stored and removed in any order. However, you cannot delete them.
The CLR's automatic GC (garbage Collector, garbage collector) automatically clears the non-master heap object when it determines that the program's code will no longer access a data item (when the reference type does not have any references).

The heap generally holds the actual data of the reference type and the stack holds the value type.

value Types : Only a single piece of memory is needed to store the actual data. (Because the stack is a memory data, storing some small space-consuming data)

Reference type : It requires two segments of memory, 1 stores the actual data, it is always in the heap, and 2 is a reference, pointing to where the data resides in the heap.

For a reference type, the data portion of its instance is always stored in the heap.
A reference to a value type object, or reference type data, can be stored in the heap or stored in a stack, depending on the actual environment.

class : A program's data and functions are organized into logically related data items and packages of functions, called classes.
class : An abstract description of something common in a realistic sense.
A class is a data structure that can store data and execute code, and each instance of a class is a different entity.

variables : When a declaration defines a variable, it accomplishes two things inside: 1. Name the variable and associate it with a type. 2 Let the compiler allocate a chunk of memory for it.
Constants : (Const) is typically an expression that consists of a predefined simple type or period. It can also be a null reference, but it cannot be a reference to an object because the object's reference is determined at run time. You cannot reassign a value in a constant.

Parameters :
Formal parameter: is a local variable declared in the parameter list of a method rather than in the method body.
Arguments: When code calls a method, the value of the formal parameter must be initialized before the code of the method begins execution.
Value parameter: (pass-through) data is passed to the method by copying the value of the argument to the parameter.
Reference parameter: (address) using the ref modifier, the argument must be a variable and must be assigned before it is used as an argument.
Output parameters: Use the out modifier to pass data to the calling code in the method body, which are very similar to reference parameters. Each output parameter must be assigned before the method reads and returns, which means that the initial value of the parameter is irrelevant.
Parameter array: Allows 0 or more arguments to correspond to a special parameter, only one argument array in a parameter list, and it must be the last one in the list. Use the (Params) modifier.

If the array parameter is a value type, then the value is copied, and the argument is not affected by the inside of the method.

If the array parameter is a reference type, then the reference is copied and the object referenced by the argument is affected by the inside of the method.

02-c# Basic definition and description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.