快明白怎么回事了,但是这个例子太绕了,绕了3天。
明明就是指针,但是这比指针还难啊。
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Test2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void nothing()
{
//ADic.Add("w", 2);
//Console.WriteLine(ADic["w"]);
//Console.WriteLine(ADic.ContainsKey("w"));
//Bitmap img = new Bitmap("C:\\ESouceCode\\Eweb-main\\易网页1.0\\photos\\宣传AND图片\\陽.png");
//pictureBox1.Image = img;
//string test = "qwerty112233445566";
//Console.WriteLine(test.Substring(0, 1));
//Console.WriteLine(test.Replace("3", "ddd"));
//Console.WriteLine(test);
//int[] intarray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
//IEnumerator theenumerator = intarray.GetEnumerator();
//while (theenumerator.MoveNext())
//{
// Console.WriteLine(theenumerator.Current);
//}
//int[] arr = new int[] { 1, 2, 3, 4, 5 };
//foreach (int i in arr)
//{
// Console.WriteLine(arr[i - 1]);
//}
//List<int> thelist = new List<int>();
//thelist.Insert(0, 1);
//thelist.Insert(0, 2);
//thelist.Insert(0, 3);
//thelist.Insert(0, 4);
//thelist.Insert(0, 4);
//thelist.Insert(0, 4);
//thelist.Insert(0, 4);
//thelist.Insert(0, 4);
//thelist.Insert(0, 5);
//thelist.RemoveAt(0);
//throw new Exception("e");
//List<int> rem = new List<int> { 4, 2 };
//thelist.RemoveAll(member => rem.Contains(member));
//thelist.Remove(4);
//foreach (int i in thelist)
//{
// Console.WriteLine(i);
//}
//Console.WriteLine(Math.PI);
//test t1 = new test();
//test t2 = new test();
//t1.SetI(2);
//t1.PrintI();
//t2.SetI(9);
//t2.PrintI();
//t1.PrintI();
//int i = 0;
//ecde(ref i);
//try
//{
// MessageBox.Show("2");
//}
//catch(OverflowException)
//{
// MessageBox.Show("3");
//}
//catch (AccessViolationException)
//{
//}
}
private void Form1_Load(object sender, EventArgs e)
{
ProductFactory TheproductFactory = new ProductFactory();
WarpFactroy ThewarpFactroy = new WarpFactroy();
Func<Product> fun1 = new Func<Product>(TheproductFactory.MakePizza);
Func<Product> fun2 = new Func<Product>(TheproductFactory.MakeToyCar);
Box box1 = ThewarpFactroy.WarpPoroduct(fun1);
Box box2 = ThewarpFactroy.WarpPoroduct(fun2);
Console.WriteLine(box1.Product.Name);
Console.WriteLine(box2.Product.Name);
}
class Product
{
public string Name { get; set; }
}
class Box
{
public Product Product { get; set; }
}
class WarpFactroy
{
public Box WarpPoroduct(Func<Product> getProduct)
{
Box box = new Box();
Product product = getProduct.Invoke();
box.Product = product;
return box;
}
}
class ProductFactory
{
public Product MakePizza()
{
Product product = new Product();
product.Name = "Pizza";
return product;
}
public Product MakeToyCar()
{
Product product = new Product();
product.Name = "Toy Car";
return product;
}
}
}
};
有没有什么更简单的例子来理解啊。
|