C # Fundamentals collation: C # Fundamentals (1)

Source: Internet
Author: User
Tags net domain
C # Basic Structure

Using system;using system.collections.generic;using system.text;namespace consoleapplication1{    class Myfirstclass    {        static void Main (string[] args)        {            Console.WriteLine ("Hello world!");            Console.ReadLine ();}}}    

(1), variable definition
<type> <name>;
example, Myfirstclass myfirstclass;
(2), how to initialize the variable
int a = 0;
String str=string. Empty;
int init = a*2;
(3), the scope of the variable
should first clarify the respective scopes for private,protected, internal, and public. The
private-is completely private and can only be called in this class, and subclasses or other classes cannot be called, and when inherited, subclasses cannot inherit private properties or methods. The
protected-is the same as private, but the difference is that the protected neutron class can access and inherit members and methods.
internal-is public, accessible in the same assembly, and not accessible by other assemblies. The
public-is completely public and can be accessed in only one project, but different assemblies need to refer to the assembly in which they are located.
The variables declared by these types are scoped to their scope;
The general variables are scoped as follows:
A, a variable belongs to a class at a scope, a property or method is also in scope.
B, the scope of the local variable, before the block statement that declares the variable or the curly brace at which the method ends.
(4), constant
when declaring a variable, you can specify the variable as a constant by adding the const keyword before the variable.
Note:
A constant must be initialized at the time of declaration, and it cannot be changed after it is assigned. The
B constant is always static, and you do not have to add the static keyword when declaring a constant. The
(5) String processing
string processing should be used more. Commonly used are as follows:

String teststring = @ "hello,world!";            Teststring.substring (0, 1);            Teststring.trim ();            Teststring.trimend (' \ n ');            Teststring.trimstart (' 0 ');

There are also, contains,startwith,endwith and so on, in vs. you can see all the methods and properties.
(6) using regular expressions
The regular application in the project or more, you can refer to the following articles:
Regular character description: http://www.php.cn/;
Common Regular: http://www.php.cn/.
(7), what is the CTS type?
A given assembly may contain any number of different "types". In the. NET domain, a type is a generic term that refers to any member of a collection {class, interface, struct, enumeration, delegate}. When used with support. NET is likely to deal with these types when building a solution. For example, an assembly might define a class, and it implements some interfaces. Perhaps one of the interface methods takes an enumeration type as an input parameter, and returns a struct when called.

The CTS (public type System) is a formal specification that specifies how a type must be defined to be hosted by the CLR. Typically, only those created for. NET Platform tool or compiler talent is very concerned about the internal work of CTS. However, for all. NET programmer, it is important to learn how to use the 5 types defined by the CTS in the language that you use. Here is a brief summary.
Every kind of support. NET language at least supports the concept of class type, which is the basis of object-oriented programming (OOP). A class can consist of many members (such as properties, methods, and events) and data (fields). In C #, use the class keyword to declare a class:

C # class type. Class calc{Public    int Add (int x, int y)    {         return x + y;     }}

Table CTS class type


Characteristics of the class

Meaning in the life cycle

Whether the class is "sealed"

Sealed classes cannot be used as base classes for other classes

Does the class implement any interfaces?

An interface is a collection of abstract members that are used in objects and objects

Provide a contract between the households. CTS allows classes or structs to implement any

What number of interfaces

Whether the class is concrete or abstract

Abstract classes cannot be created directly, but can be used to send

class defines the behavior of the public. Specific classes can be created directly

What is the visibility of this class?

Each class must have visibility set. Basically, visibility defines the

is the class used by an external assembly, or is it only possible to define it

The Assembly uses


(8) How are data types categorized and each data type range?
http://www.php.cn/
(9) operator
Parentheses operator
Format ()
Dot operator
Format (E.I)
where e is the basic expression or predefined type, I is an identifier. Except for "." in C + +. In addition to the "::" "," C # with the dot operator instead. For example, a class T has a member variable M, which is referenced in C + + with t::m, and T is used in C #. M to reference. Another difference is that the predefined type in C # is also derived from the object class, so the member variable is also defined, for example, I is a short type of variable, then I. The ToInt () operation returns a value of type int.
postfix addition and subtraction operator
Format: p++;p--; ++p; --p;
The result is to add 1 or minus 1 to the variable p.
New operator
Format: A, new type (parameter list)
B,new Array type initialization list
C,new delegate type (expression)
typeof operator
The operation returns the system for a type. Type, such as:

typeof (int); typeof (System. INT32); typeof (String);


The individual results for int32,int32,string. typeof only for type operation and cannot be changed to
For example, "int i;typeof (I);" It's not legal.

sizeof operator
This operation obtains the amount of space occupied by a type, in bytes, as a single
-bit This operator is used in unsafe modules, such as

unsafe{s=sizeof (int);}

or use that prefix in a function that calls the operator.
Monocular operator
(1) +-operation
(2) Logical non-:! (expression)
(3) Bit non: ~ (expression)
(4) Coercion type conversion: (T) expression
Relational operators
==,!=,,=, is
is used to determine whether a variable is a certain type, for example, S is string
Bitwise logical Operators
& (Bit and), | (bit or), ^ (XOR). can be on integers, booleans, and pieces
These three types of operations.
Conditional logical operators
including && (with) and | | Or
Conditional operators
b x:y
B is true, the result is x, otherwise y

The above is the basic knowledge of C # collation: C # Basic (1) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.