using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 面向对象集合
{
class Program
{
static void Main(string[] args)
{
//创建一个集合对象
ArrayList list = new ArrayList();
//集合:很多数据的一个集合
//数组:长度不可变,类型单一
//集合的优点:长度可以任意改变,类型也不固定。
list.Add();
list.Add(3.14);
list.Add(true);
list.Add("张三");
list.Add('男');
list.Add(5000m);
list.Add(new int[] { , , , , , , , , });
person p = new person();
list.Add(p);
list.Add(list); //没有判断的情况下输出的是集合ArrayList的命名空间
for (int i = ; i < list.Count; i++)
{
// Console.WriteLine(list[i]);
if (list[i] is person)
{
((person)list[i]).Sayhello();
}
else if (list[i] is int[])
{
for (int j = ; j < ((int[])list[i]).Length; j++)
{
Console.WriteLine(((int[])list[i])[j]);
}
}
else
{
Console.WriteLine(list[i]);//未判断
} }
Console.ReadLine();
}
public class person
{
public void Sayhello()
{
Console.WriteLine("我是人类");
}
}
}
}
            list.AddRange(new int[] { , , , , , , , ,  }); //添加集合用AddRange
for (int i = ; i < list.Count; i++)
{
Console.WriteLine( list[i]);
}
Console.ReadLine();

面向对象之集合ArrayList的更多相关文章

  1. java基础小练习,1-打印一百次(1~10)的随机数,2-固定一个随机数(1~100),然后猜出他,3-定义以指定格式打印集合(ArrayList类型作为参数),使用{}括起来,使用@代替,分隔每个元素

    推荐自己码一下,可以使用别的方法,面向对象,不需要注重过程 /* 题目:我需要打印一百次(1~10)的随机数 */ import java.util.Random; public class demo ...

  2. Java ArrayList和Vector、LinkedList与ArrayList、数组(Array)和列表集合(ArrayList)的区别

    ArrayList和Vector的区别ArrayList与Vector主要从二方面来说.  一.同步性:   Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步 ...

  3. 集合ArrayList

    /*集合ArrayList * 例如: * 1.创建:ArrayList<Egg> myList = new ArrayList<Egg>(); *      Egg类型的集合 ...

  4. 集合及特殊集合arrayList

    1,运用集合  arrayList 首先复制Colections加  : 创建arrayList ar =new arrayList(); ArrayList具体提供的功能:属性            ...

  5. Java 集合 ArrayList和LinkedList的几种循环遍历方式及性能对比分析 [ 转载 ]

    Java 集合 ArrayList和LinkedList的几种循环遍历方式及性能对比分析 @author Trinea 原文链接:http://www.trinea.cn/android/arrayl ...

  6. 数组Array和列表集合ArrayList、LinkedList和Vector的区别

    一.ArrayList和Vector的区别 ArrayList与Vector主要从以下方面来说. 1.同步性: Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同 ...

  7. 第三章泛型集合ArrayList 和Hashtable

    第三章泛型集集合 ArrayList 变量名 = new ArrayList();  //相当与一个容器 他的执行using 是  using System.Collections; 变量名.ADD( ...

  8. JAVA基础——集合——ArrayList

    ArrayList集合 ArrayList的一些方法(JDK1.8): 将指定的元素附加到列表的末尾,true:添加成功,false:添加失败: public boolean add(E e)    ...

  9. 反射方式,获取出集合ArrayList类的class文件对象

    /* * 定义集合类,泛型String * 要求向集合中添加Integer类型 * * 反射方式,获取出集合ArrayList类的class文件对象 * 通过class文件对象,调用add方法 * * ...

随机推荐

  1. poj 1163 The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43809   Accepted: 26430 De ...

  2. 百度BAE环境下WordPress搭建过程

    参考: 文章一:http://capbone.com/bae-wordpress/ 文章二:http://tieba.baidu.com/p/2612184581 注意点: wordpress 下载地 ...

  3. 第三章 Models模块属性详解

    摘自:http://www.cnblogs.com/xdotnet/archive/2012/03/07/aspnet_mvc40_validate.html 了解了这些就可以对MVC进一步认识,相信 ...

  4. SSH公钥认证+优化

    一 ssh公钥认证流程: sshclinet机器:产生公私钥(公钥相当于一把锁) sshclient:将公钥发给sshserver(抛出锁子) sshclinet去连sshserver不需要密钥   ...

  5. Maximum Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  6. Windows7+VS2012下OpenGL 4的环境配置

    系统环境 Windows 7 Ultimate x64,Visual Studio Ultimate 2012 Update 4,和一块支持OpenGL 4.x的显卡. 准备工作 首先用GPU Cap ...

  7. Windows和Linux上用C与Lua交互

    Windos2010编译lua的方法: http://blog.csdn.net/appletreesujie/article/details/12065369 Linux编译lua的方法: make ...

  8. windows命令行

    [drive:] Change the current driver, without changing its current directory cd [drive:] [path] Just c ...

  9. IOS开发之——CocoaPods安装和使用 OC和swift通吃

    网址一:步骤 http://blog.csdn.net/showhilllee/article/details/38398119 网址二:为什么这么做(原因) http://blog.csdn.net ...

  10. 工作随笔——xshell4安装后应该做的一些事

    xshell4默认支持中文语言 选项→键盘和鼠标:设置快捷键,鼠标按键(可以提高工作效率) 1.选定文本自动复制到剪贴板 选择→将选定的文本自动复制到剪贴板(选上) 2.更高鼠标中间按钮和右键按钮的功 ...