Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basics of C#

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the basics of C#". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "what are the basics of C#".

1. Classification of data types in C#:

(1) value type: it is stored in the stack of memory and represents the actual data. Including: basic data types (except strings), structures, enumerations.

(2) reference type: it is stored in the memory heap and represents the object address. Including: string, array, class, interface, delegate.

2. The declaration method of C# declaration constant:

(1) static constant (const):

< 访问修饰符>

Data type constant name = constant value

(2) dynamic constant (readonly):

Static constant of basic knowledge of C # (const)

Definition: set the constant value at the same time as the declaration.

Type restriction: first of all, the type must be within the range of the value type, and its value cannot be set through new.

For class objects: for objects of all classes, the constant value is the same.

Memory consumption: none.

Summary: slightly higher performance, no memory overhead, but quite limited and inflexible.

Dynamic constant of basic knowledge of C # (readonly)

Definition: the constant value can be set without setting the constant value when declared, but can be set in the constructor of the class.

Type restrictions: there are no restrictions, and you can use it to define constants of any type.

For class objects: the values of constants can be different for different objects of the class.

Memory consumption: to allocate memory, save constant entities.

Summary: flexible and convenient, but with slightly lower performance and memory overhead.

3. Packing and unpacking:

(1) boxing: converts a value type to a reference type. (is as)

(2) unboxing: convert the reference type to the value type.

4. Typeof operator:

C # does not have its own library, but it shares the library of .net. The basic data type in C # is just an alias for the .net basic data type. Gets the type of the system prototype object.

5. Access domain and access modifier

(1) access domain: public, private, internal, protected, protectedinternal

(2) access modifiers: partial, sealed, virtual, override, abstract, new, extern, static

6. Constructors and destructors:

(1) Constructor: with the same name as the class, no return value is returned. It can be reloaded.

(2) Destructor: it has the same name as the class and has no return value. Cannot be reloaded. A class has only one destructor. Automatically called by the garbage collector.

7. Call the constructor:

(1) call the basic constructor:: base () or: base (string name,int age)

(2) call the base class common method: base. Base class method name ()

8. Method call:

(1) instance object call: class name. Method name ([parameter list])

(2) static class call: class name. Method name ([parameter list])

9. Method overloading and method rewriting:

(1) method overloading: methods in the same class have the same return type, the same method name, and different method signatures.

(2) method rewriting: in the base class and subclass, the base class method can be overwritten with override in the subclass only when the base class methods are virtual or abstract.

10. Three major features of OOP programming:

(1) encapsulation:

(2) inheritance:

(3) Polymorphism: two forms of polymorphism: method overloading and method rewriting.

11. the difference and relationship between abstract classes and interfaces:

Abstract class of C # basics: a class that contains at least one abstract method cannot be instantiated. Contains properties, method declarations, function definitions, and implementations.

Interface to the basics of C #: interface is a special abstract class. Is limited to the declaration of methods, indexers, and properties.

12. Entrust:

(1) it contains a reference to the method instead of the method name, and the delegate allows you to dynamically set the method to be called at run time. The delegate connects the name to the definition of the method.

(2) the role of delegate: define event handle (EventHander), purpose: customize the event. A delegate is actually a pointer to a function, which can refer to a function.

(3) steps to use a delegate:

A defines delegate: [access modifier] delegate returns the type delegate name ()

B instantiate the delegate to point to a method.

C use delegation:

13. Events:

(1) Event: a function member that sends messages from classes and objects. To notify that a particular action has taken place or that a particular condition has been established.

Define events:

[access modifier] event delegate name event name

When defining an event, the publisher first defines the delegate, and then defines the event based on the delegate.

Public delegate void delegateMe () / / define delegation

Public event delegateMe eventMe; / / define events

(2) subscription event: only a delegate has been added, and the delegate will call a method when the event is raised.

Subscribe to events:

The eventMe+=new delegateMe (objA.Method) / / objA.Method method subscribes to the event eventMe

14. Controls and components:

(1) controls: visual interface components are called controls. (visual classes), all Windows forms are classes derived from the System.Windows.Forms.Control class.

(2) components: there is no visual interface.

The above is all the contents of the article "what are the basics of C#". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report