惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
罗磊的独立博客
B
Blog
博客园_首页
A
About on SuperTechFans
有赞技术团队
有赞技术团队
V
V2EX
U
Unit 42
I
InfoQ
IT之家
IT之家
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
H
Help Net Security

博客园 - shcity

Troubleshooting on TransactionScope Parse string to JSON object Parse date in js blockUI doesn't close when download file in asp.net define namespace in JS Dense_Rank(), Row_Number(), Rank() in sql server reading and writing variable through lock in SSIS script task Fix the issue that cannot open SSIS in BIDS three ways creating custom helpers to show RadioButtonList in MVC using JavaScriptSerializer to serialize object to json using ISerializable to control serialization and deserialization ViewStateAutoManager ReportingService formatting Build my own DataTable split a string into an array through comma div with separated html template - shcity 正则表达式替换日期 半透明的div对话框 在Ajax1.0中调用页面CS文件中的方法
foreach 的自动转化类型
shcity · 2007-12-05 · via 博客园 - shcity

namespace WindowsApplication9
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            
object[] persons = new object[3];
            persons[
0]=(new Person("x"));
            persons[
1= (new Person("y"));
            persons[
2= (new Person("z"));

            
//从persons中取出的成员是object类,foreach会自动将其转化为目标类型
            foreach (Person person in persons)
            
{
                MessageBox.Show(person.Name);
            }
 
        }

    }


    
public class Person
    
{
        
public string Name;

        
public Person( string n)
        
{
            
this.Name = n;
        }

    }

}

posted on 2007-12-05 16:55  shcity  阅读(380)  评论(0)    收藏  举报

刷新页面返回顶部