Home > Net >  Of new bosses for help all of you!
Of new bosses for help all of you!

Time:09-26

 using System; 
Using System. Collections. Generic;
Using System. The Text;
Using System. Windows. Forms;
Using System. The Collections;

The namespace Xuexi
{

Class Program
{
The static void Main (string [] args)
{
ProductFactory ProductFactory=new ProductFactory ();
WrapFactory WrapFactory=new WrapFactory ();

Func Func1=new Func (productFactory MakePizza);
Func Func2=new Func (productFactory MakeToyCar);

Box box1=wrapFactory. WrapProduct (func1);
Box box2.=wrapFactory WrapProduct (func2);

Console. WriteLine (box1. Product. Name);
Console. WriteLine (box2. Product. Name);



Console.ReadKey();
}
}

The class Product
{
Public string Name {get; The set; }

}

The class Box
{
Public Product Product {get; The set; }

}

The class WrapFactory
{
Public Box WrapProduct (Func GetProduct)
{
Box Box=new Box ();
The Product the Product=getProduct. Invoke ();
Box. The Product=Product;
Return the box;
}
}

The class ProductFactory
{
Public Product MakePizza ()
{
The Product the Product=new Product ();
Product. The Name="Pizza";
Return the product.
}

Public Product MakeToyCar ()
{
The Product the Product=new Product ();
Product. The Name="ToyCar";
Return the product.
}
}

}




I am one of the new, this code have some want to consult everybody bosses, grateful!

1, the method of public behind why the return type is the Product can use the name of the class? In the name of the class what is the point?
The class Box
{
Public Product Product {get; The set; }

}

CodePudding user response:

This is not the way, this is the Property, the Property

CodePudding user response:

Nothing special meaning, one is the name of the class, a property name

CodePudding user response:

On, the Product here as the entity object, can return to a physical object, the Product with corresponding database tables, this object can be members can also return the custom, the Name is the member variable, you can also add the age, sex, such as tel members back together, if you want to put in storage, you can write this object as a parameter to the library, so write the benefits of the code is simple, easy to maintain,

CodePudding user response:

Based tutorial https://docs.microsoft.com/zh-cn/dotnet/csharp/properties can see,

CodePudding user response:

Basis according to the Chinese version of this tutorial is roughly study again,

CodePudding user response:

Box class of Product attributes, only the Product types of data information

CodePudding user response:

The product as an attribute,
  •  Tags:  
  • C#
  • Related