C # Object-oriented-object member, method overloading, reference class library, etc.

Source: Internet
Author: User

First, method overloading:
1. Two functions have the same name, and they form the overloaded relationship of the method
2. Overloaded functions, must have different parameter types or number of arguments from other functions

Ii. Fields and properties
Fields of the class:
Classes can be directly defined variables, which are called class fields, also called member variables.
Properties of the Class (spanner):
itself does not store data, an access procedure used to assign and value a field. You can protect a field.
Includes two functions of read accessor and write accessor;

Read accessor
get {return Name;}
Write accessors
set {
if (value. LENGTH<=3)
Name = value;
}

Set properties for a field (member variable):
Step: Right-click on the field--refactor--encapsulate field

Iv. Static Members:
Cannot operate through the object of a class, only by using the class name.
After a class creates an object as a template, the object cannot call static members directly, but static members can be accessed through instance methods (note: Static members that are accessed by instance methods of different objects are the same static members).

V. The difference between a class and an object:
Class is a user-defined data type and is a template
An object is a variable created by a template.
The relationship between a class and an object is a one-to-many relationship, and the class can create N objects based on the class.

Vi. Constructors for classes
In vs2012, the name is followed by a parenthesis (), which is a function.
syntax when creating an object: Class1 aaa=new Class1 ();
Here, in fact, new calls a function;
Class1 () This is a function in which each class has a default, called a constructor;
The constructor is the entry of the class when the object is created.


Constructor features: The same name as the class name, default no return value, no parameters, no function body, can write overloaded, with all the functions of ordinary functions.


Function: The initial value of the member variable is given when the object is created;
You can make interactions between classes and classes.


Seven, modifier:
Public, scoped to the entire namespace (class library), and other places where this namespace is referenced
Private, can only be used for the current class
Protected protected, for the current class, and for subclasses

VIII. Namespaces and class libraries
(a) namespaces: It's like a folder, it's for the area to be stored in, a project corresponds to a namespace.

You can right-click a solution, open a folder in Solution Manager, and view the files in the solution


. SLN solution, double-click Open Solution
. csproj Project


After you change the namespace of the class, the folder where the class is located changes, and the original local class is not available unless you add using+ to the new namespace name.

How do I refer to a new class?
Write the class name (can not have errors, case-sensitive), the mouse on the class name, there will be a small triangle, click to add the namespace where the class, the class is available.

Citation succeeded

In essence, namespaces are not folders, and changing the namespace of a class does not create a new folder, but rather an assembly that holds a variety of classes, which we call class libraries.

Referencing a namespace, the class library is compiled into the project's Debug folder (. DLL).

How do I create a new class library (project) and reference it in another project?
1. New Class Library: New project and Class library;
Write Good class;
Then right-click the project--build,

The folder of the class library in debug appears (. dll) file,


2. Referencing a class library in another project: right-clicking a reference in a project, adding a reference,


In the pop-up window, locate the Debug folder for the class library and select the. dll file;
Right-click Project, build, two more files in the debug file of the project,


Add a namespace: Using + Class library name
You can call the class: Class Library name. Class Name

A class that calls other class libraries is actually adding files such as DLLs to other class libraries to the Debug folder of the project.

C # Object-oriented-object member, method overloading, reference class library, etc.

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.