Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; namespace happyproject{public class Happy {public const string Slogan = "is happy!"; Private DateTime when; private string why; Public DateTime when {get; set;} public string Why {get; set;} } public class unhappy {public const string Slogan = "is unhappy!"; Private DateTime when; private string why; Public DateTime when {get; set;} public string Why {get; set;}} }
Writing two classes, it's no use.
The data and functions in the class are called members of the class. The accessibility of a member can be public, protected, internal, private.
data members are data containing classes, nonsense, fields (field), constants, my two classes all have the ~ event my class has not yet. Data members can be static or instance members.
- An event is a member of a class that allows an object to notify the caller when certain behavior occurs, such as changing a field or property of a class, or some form of user interaction. The customer can include the code of the so-called "event handler" in response to the event, and later on, the tree is not what I said.
function members provide some functionality for manipulating data in a class. Includes methods, properties, constructors, and finalizers (finalizer), operators, and indexers. A function member can be static or an instance member (default).
- Property was a method group which we can visit from client. How to visit? Object.property. C # provides specialized syntax for properties in both read and write classes, so it is not necessary to use methods that have a get or set embedded in their names. Because this syntax of a property differs from the syntax of a general function, in the client's code, the virtual object is treated as the actual thing.
- The constructor constructor is a special function of the Auto-invoke that is automatically called when an object is instantiated. They must have the same name as the owning one, this knows, and cannot have a return type. The constructor is used to initialize the value of the field.
- Finalizer is something like constructor. When the CLR detects an object won ' t is used any more, it would invoke finalizer. Their name is the same with Class, but have a bolang line. Check it out, call Tlide. Attach this.
"-" is called "dash" (Chinese long), belongs to Chinese use, in English called "dash";
"-", called "Connection Number" (English short), belongs to the English-specific, called "hyphen"
"_" is underlined, English is: underline
+ Plus plus;
-Minus minus sign;
±plus or minus plus sign
XIs multiplied by multiplication sign
÷is divided by Division sign
= is equal to equals sign
≠is not equal to no equal number
≡is equivalent to full equals sign
≌is equal to or approximately equal to equals or approximately equals sign
≈is approximately equal to approximately equals sign
< is less than
> is more than greater than
≮is not less than
≯is not more than no greater than No.
≤is less than or equal to lesser than or equal to number
≥is more than or equal to greater than or equal to number
% per cent percent ...
‰per Mill thousand ...
∞infinity Unlimited Size
∝varies As with ... Proportional
√ (square) root square root
∵since; Because because
∴hence so
∷equals, as (proportion) equals, proportional
∠angle, PTA.
⌒semicircle semicircle
⊙circle Round
0circumference circumference
Πpi Pi
Triangle Triangle
⊥perpendicular to perpendicular to
∪union of And, collections
∩intersection of sex, thong set
∫the Integral of ... The integral
∑ (sigma) Summation of sum
°degree degree
′minute min
″second sec
℃celsius system Celsius
{Open brace, open curly left curly brace
} Close brace, close curly right curly brace
(openparenthesis, open paren left parenthesis
) Close parenthesis, close paren right parenthesis
() brakets/parentheses Brackets
[Open bracket left bracket
] Close Bracket Right bracket
[] square brackets square brackets
. period, dot period, dot
| Vertical bar, vertical virgule vertical Line
&ersand, and, reference, ref and, reference
* Asterisk, multiply, star, pointer asterisk, multiplication sign, star, pointer
/Slash, divide, oblique Slash, slash, division sign
Slash-slash, comment Double slash, annotation character
# Pound well No.
\backslash, sometimes
Escape Backslash escape character, sometimes indicating escape character or line continuation character
~tilde Wave character
. Full Stop Period
, comma comma
: Colon Colon
; Semicolon semicolon
? Question mark question mark
! Exclamation mark (British English) exclamation point (American English)
' Apostrophe apostrophe
-Hyphen hyphen
--Dash Dash
... dots/ellipsis ellipsis
"Single quotation marks apostrophe
"" Double quotation marks quotation marks
‖parallel Double line number
& ampersand = and
~swungdash Tilde
§section; Division Sub-section number
→arrow Arrow; see the number
- Operator Override.
- Index QI Indexer allowed the objects to is indexed with array or collection.
Next, the book began to talk about
method declaration, the method call will be.
Public double tobehappy (double cost) {
Double left=cost;
LEFT-=EATINGKFC ();
Left-=buyadress ();
Left-=readingbooks ();
Left-=dosports ();
return left;
}
The one I'm interviewing for. The value passed or the reference pass parameter.
Duang! Core section: passing parameters to a method
Parameters can be passed to a method by reference or by value.
- When a variable is passed to a method by reference , the called method gets the variable, so any change to the variable within the method is still valid after the method exits.
- The variable is passed to the method by value passing , and the method that is called is given an identical copy of the variable, that is, after the method exits, the changes to the variable are lost.
For complex data types, it is more efficient to pass by reference, because large amounts of data must be copied when passing by value.
In C #, unless specifically stated, all parameters are passed by value values. But, when you understand the meaning of a reference type, you need to be aware. What are reference types? Forget the again. I remember a class.
Tonic, think of the Kingdom of Wu too.
This is my good husband!
Find, when the exchange of wending things!
I am the mother of Wu, who dares to act up!
There is laoshen in, you can rest assured!
The CLR supports two types of images that are stolen, http://www.cnblogs.com/siqing99/archive/2012/04/03/2430918.html
All value types in C # are implicitly derived from System.ValueType.
C # VALUE type: Structure!!!! Nullable type nullable!!!! numeric type int double what's!!! Value type on the stack
C # Reference types: Array arrays!!!! Class!!!! Interface!!!! Commissioned!!!! String!!!! object!!!! On that escrow heap, garbage collector
Memory allocation of a few points, in the above blog see, not copy, but typing to play.
when a value type is a local variable, the instance is created on the stack, and if the value type variable is a member of the type, it will be part of the data for the type instance, for example, why in the happy class above, as well as other fields of that type, on the managed heap. is the so-called nested structure.
Reference type variable data is persisted on the managed heap, but differs depending on the size of the instance. as follows, when the instance size is less than 85000Byte, the instance is created on the GC heap, and when the instance is too large, the instance is created on the Loh (large object heap).
There are two cases of nesting. A reference type is nested within a value type, and a struct has a member that is a class. The reference type will be the member variable of the value type, the member's reference is saved on the stack, and the actual data of the member is on the managed heap.
In the second case, the reference type is a nested value type, and the value type is a member of the managed heap. If it is a local variable in a function member, it is still the same as the home of the value type, on the stack.
The tonic is over!
Note that the string behaves differently because the string is immutable, and you are hard to change its value, creating another string object. Therefore, a string cannot behave in a generic reference type. In a method call, any changes made to the string do not affect the original string.
The default value is passed, and C # requires that parameters passed to the method be initialized, no matter passing parameters by value or by reference, and initializing variable is important.
You want to pass the default value to a reference pass, using the ref keyword .
static void Study (ref int hours)
{
hours++;//i don ' t like C #, but I don't like Java, too.
}
Sometimes, what if we want to output multiple values from the execution of a function? use the Out keyword. The value of the passed parameter is not cared for at this time, but the rule must be initialized and the compiler will initialize it with the Out keyword. An out prefix is prepended to the input parameters of the method, and the variables passed to the method can be uninitialized. The variable is passed by default reference.
Learn so much today ~tlide~ will recite some words later! I really do not love to study Ah! I'm so lazy! Change yourself! A little change! If anyone accidentally saw this article, get rid of the other, don't waste time ~
String Printhappy (String when, string why) {
Return when+ "" +why;
}
When you invoke this method, you needn ' t pass parameters in the order of definition.
Like this, Printhappy (why: ' I picked up some money ' on the the-the-same-", When:" 8 pm ");
So how about the parameters? Sick of it! There is an optional parameter that has been used before. Some parameters you can assign a default value to it, but the optional parameter must be the last parameter of the method definition.
int TestMethod (int notopetionalnumber, int optionalnumber=10) {}//Mandatory
Optional parameter cannot be overloaded with methods. The method name is the same, the return type can be different, but the return type is different as the basis for judging them.
Oh! After reading, the next section is a property! Basic will, write tomorrow!
Introduction to C # classes, parameter passing, various symbolic sayings