C # anonymous object (anonymous type), var, dynamic type dynamic,
This article is the prelude to the next article "C # reflection and optimization usage". It is not the foundation of the next article. If you are interested, please pay attention to it.
With the development of C
Many people may not be familiar with the inner class mentioned in Java. In fact, similar concepts also exist in C ++, that is, nested class (nestedClass). The differences and relationships between the two are compared in the following section. On the surface, an internal class defines another
Public interface contents { Int value (); } Public interface destination { String readlabel (); } Public class goods { Private class content implements contents { Private int I = 11; Public int value (){ Return I; } } Protected class gdestination implements destination { Private string label; Private gdestination (string whereto ){ Label = whereto;
1. Anonymous type in C #
The anonymous type is a new feature introduced in C #3.0 (framework3.5. As the name implies, an anonymous type is an object without a type name, which inherits directly from the object.
The C #
The relationship between a type, a variable, and an instance.Type "Variable" exampleTypes can create variables, entity classes can create instances, and instances can be stored in variables.Second, the use of the Commission process:1. Define the delegate (write a good signature);2. Create a delegate variable;3. Place the function (the same signature) in the delegate variable.Event: A variable defined with a pre-defined delegate (Eventhandle) (receives two parameters).The form has a delegate vari
corresponding object to invoke the interface, this process is called an interface callback for the object functionCross-class references1) If a is a reference to Class A, then a can point to an instance of Class A. Or the one that points to class ASub-class, which is a case
Today, I saw several concepts in the Code: internal class, local class, member class, static member class, and anonymous internal class. I felt confused in an instant. Below is a small example to illustrate them:
Public
create an internal class to implement this interface. Since all the content of the internal class is accessible to external departments, this can complete all the functions that you can directly implement this interface.
But you may have to question it. Isn't it enough to change the method?
Indeed, it is unconvincing to use this as a reason to design internal classes.
The real reason is that the internal c
Anonymous Methods is one of the new features of c#2.0, which allows us to create a built-in method with no method name in the code, associate code with a delegate instance, which makes the instantiation of the delegate more intuitive and convenient, and improves the readability and maintainability of the code. Here's a simple way to use anonymous methods:
Privat
name. Internal class name ();* Static members cannot be defined in a non-static member inner class8. The face question of the members ' inner classRequirements: Use known variables in the console output 30,20,10. classOuter { Public intnum = 10; classInner { Public intnum = 20; Public voidShow () {intnum = 30; SYSTEM.OUT.PRINTLN (num); System.out.println ( This. Num); System.out.println (Outer. This. Num); } } }
Visual
Anonymous Method Basics
The anonymous method is a new language feature of the c#2.0. The main content of this article is to provide readers with a better understanding of the internal implementation and working methods of anonymous methods. This article is not intended to be a complete language attribute refer
++ ++ ++Internal class, local internal class, anonymous internal class++ ++ ++/*** * Usage reason:1. Internal class method, which can access the data in the scope of the 2. The internal class can be hidden from 3. When you want to
Anonymous classes are classes that cannot have names, so there is no way to reference them. They must be declared as part of the new statement when they are created. This will take another form of the new statement, as follows: New Java code
Copy Code code as follows:
Interface PR
{
void Print1 ();
}
public class Nonameclass
{
Public PR Dest ()
{
return new PR () {
public v
Anonymous methods is one of the new features of C #2.0, which allows us
Code Create a built-in method without a method name and associate the Code with the delegated instance. This makes the delegation instantiation more intuitive and convenient, and improves the readability and maintainability of the Code. The following describes how to use a simple anonymous m
The relationship between a type, a variable, and an instance.Type "Variable" exampleTypes can create variables, entity classes can create instances, and instances can be stored in variables.Second, the use of the Commission process:1. Define the delegate (write a good signature);2. Create a delegate variable;3. Append the reference function (same signature) to the delegate variable.Iii. The origin of lambda expressionsprivate void Button1_Click (object sender, EventArgs e) { //
C + + Anonymous union,struct--Anonymous consortium and bodyThe basic usage of the structure and the consortium is not to be mentioned, but only for the information they visit when they are anonymous. If the token is different, you can access it directly across tiers. Example
#include >
using namespace Std;
s
empty object/collection, with no attributes and object b=new {}; varBB =New{UserName ="Jack.chen", Sex ="male", age = -, Address ="China-Suzhou"};//The BB will be parsed into an object with properties and the Preson type is exactly the same. varBBB =New[] {NewPreson {UserName ="Jack.chen", Sex ="male", age = -, Address ="China-Suzhou"},NewPreson {UserName ="Loose-li", Sex ="female", age = -, Address ="China-Shanghai"},NewPreson {UserName ="Cathy", Sex ="female"} };//The BB
Anonymous classes cannot be referenced because they cannot have names. They must be declared as part of the new statement at creation. This requires another form of new statement, as shown below: new Java code
Copy codeThe Code is as follows: interface pr
{
Void print1 ();
}
Public class noNameClass
{
Public pr dest ()
{
Return new pr (){
Public void print1 ()
{
System. out. println ("Hello world !! ");
}
}
The difference between inner class and anonymous inner class in Javainner class: The inner class can be static or non-static, static and static class variables can only be included, only static elements of the outer
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.