• IEnumerable接口


    实现IEnumerable接口的类可以进行简单迭代,例如foreach语句
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;

    namespace IEnumerable接口
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                A a 
    = new A();
                
    foreach (int? var in a)//当int值可能被赋空值时用?

                
    {
                    Console.WriteLine(var);
                    
                }


            }

        }

        
    class A : IEnumerable
        
    {
            
    int x = 1;
            
    int y = 2;
            
    int z = 3;
            
    public IEnumerator GetEnumerator()
            
    {
               
    // int i = -1;
                for (int i = 0; i <=3; i++)
                
    {


                    
    if (i == x)
                    
    {
                        yield 
    return 1;
                    }

                    
    else if (i == y)
                    
    {
                        yield 
    return 2;

                    }

                    
    else if (i == z)
                    
    {
                        yield 
    return 3;

                    }

                    
    else
                    
    {
                        yield 
    return null;
                    }

                }

            }

        }

    }

    肩负责任,永不退缩
  • 相关阅读:
    使用VPD解决EBS中信息屏蔽问题
    How to set window title name on Oracle EBS Form?
    FORM-加载前指定日期时间格式
    ORACLE EBS FORM 二次开发常用小技巧
    OM-销售订单行【订购项目】配置参数文件控制
    FORM动态LIST ITEM
    如何在form初始化时自动隐藏FOLDER列
    IIS整合tomcat
    从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
    C语言基本数据类型简介
  • 原文地址:https://www.cnblogs.com/ATP/p/860660.html
Copyright © 2020-2023  润新知