试管婴儿哪个医院比较好

试管婴儿哪个医院比较好【正规试管婴儿医院】【微*电138*0226*9370】在我国民间经常把“体外受精和胚胎移植”(IVF-ET)叫“试管婴儿”。而事实上,体外受精是一种特殊的技术,是把卵子和精子都拿到体外来,让它们在体外人工控制的环境中完成受精过程,然后把早期胚胎移植到女性的子宫中,在子宫中孕育成为孩子。利用体外受精技术产生的婴儿称为试管婴儿,这些孩子也是在妈妈的子宫内长成的。可以说,“试管婴儿技术”等同于“体外受精”。

一、枚举器和可枚举类型

1.0   一个简单的例子

复制代码
1     static void Main(string[] args)
2         {
3             int[] arr = { 2,3,5,8};
4             foreach (int item in arr)
5             {
6                 Console.WriteLine("item's Value is :{0}",item);
7             }
8             Console.ReadKey();
9         }
复制代码

  上边例子通过foreach依次取出数组中的元素并打印,为什么数组能够实现这种操作呢?原因是数组可以按需提供一个 枚举器对象 。枚举器可以依次返回请求中数组中的元素,枚举器知道元素的顺序并跟踪元素在序列中的位置,然后返回请求的当前项,我们可以通过GetEnumerator方法获取枚举器对象。

1.1  IEnumerator接口

实现IEnumerator接口的类型就是枚举器,该接口有三个函数成员:

   Current :获取当前位置元素

   MoveNext :把枚举器位置前进到下一项,返回bool,表示位置是否有效(超出就无效返回false)

   Reset :把位置重置为原始状态的位置(有索引是一般为-1)

知道这些后我们可以自己实现上边例子的foreach操作:

复制代码
 1      static void Main(string[] args)
 2         {
 3             int[] arr = { 2,3,5,8};
 4             //获取arr的枚举器
 5             IEnumerator ie = arr.GetEnumerator();
 6             while (ie.MoveNext())
 7             {
 8                 int i = (int)ie.Current;
 9                 Console.WriteLine("item's value is:{0}",i);
10             }
11             Console.ReadKey();
12         }
复制代码

1.2  可枚举类型

 可枚举类型 :实现了IEnumerable接口的类,IEnumerable只有一个成员GetEnumerator方法,用于获取枚举器(IEnumerator接口的实例)。

二、迭代器

  通过IEnumerable和IEnumerator我们已经可以实现可枚举类和枚举器,在C#2.0中提供了更简单的创建枚举类型和枚举器的方式:迭代器。我们使用迭代器时,编译器为我们创建可枚举类型和枚举器。

迭代器块 :有一个或多个yield语句的代码块

      yield return :指定了序列中返回的下一项

      yield break :指定在序列中没有其他项

迭代器创建可枚举类型和枚举器的两种模式:

①一个迭代器创建枚举器的栗子

复制代码
 1     class Color
 2     {
 3         //实现了IEnumerable的GetEnumerator方法
 4         public IEnumerator<string> GetEnumerator()
 5         {
 6             return SomeColor();
 7         }
 8         //迭代器,返回一个IEnumerator类型
 9         public IEnumerator<string> SomeColor()
10         {
11             yield return "red";
12             yield return "green";
13             yield return "yellow";
14         }
15     }
16     class Program
17     {
18         static void Main(string[] args)
19         {
20             Color color = new Color();
21             foreach (string item in color)
22             {
23                 Console.WriteLine(item);
24             }//output:red green yellow
25         }
26     }
复制代码

②一个迭代器创建可枚举类型的栗子:

复制代码
 1     class Color
 2     {
 3         //GetEnumerator方法
 4         public IEnumerator<string> GetEnumerator()
 5         {
 6             return SomeColor().GetEnumerator();
 7         }
 8         //迭代器,返回一个IEnumerable类型
 9         public IEnumerable<string> SomeColor()
10         {
11             yield return "red";
12             yield return "green";
13             yield return "yellow";
14         }
15     }
16     class Program
17     {
18         static void Main(string[] args)
19         {
20             Color color = new Color();
21             foreach (string item in color)
22             {
23                 Console.WriteLine(item);
24             }//output:red green yellow
25         }
26     }
复制代码

值得注意的地方:

复制代码
① 使用迭代器,在编译器中生成的枚举器在后台是一个包含四个状态的状态机

  1、Before:首次执行MoveNext()的初始状态

  2、Running:执行MoveNext()后进入这个状态,枚举器检测并设置下一项的位置

  3、Suspended:等待下次调用MoveNext()

  4、After:没有更多项可以枚举

② 在遍历IEnumerable<T>时,yield return 和return的区别:

  yield return告诉编译器这是一个迭代器,每次只返回当前位置的值,即“按需返回”

  return则将所有的值加载到内存,“一次加载”
复制代码

猜你喜欢

转载自www.cnblogs.com/shiguanyinger/p/9449081.html
今日推荐