摘要: /// <summary> /// 自定义List /// </summary> /// <typeparam name="T">列表中元素的类型</typeparam> class MyList<T> : IEnumerable { T[] t = new T[0]; public MyList() { } public MyList(int capacity) { this.Capacity = capacity; } int count = 0; /// <summary> /// MyList& 阅读全文
posted @ 2011-07-28 20:06 贺俊峰 阅读(563) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;namespace MyArrayList_hjf{ class MyArrayList : IEnumerable { object[] objarr = new object[0]; int count; public MyArrayList() { } public MyArrayList(int capacity) { this.Capacity = capacity; } 阅读全文
posted @ 2011-07-20 19:37 贺俊峰 阅读(838) 评论(0) 推荐(0) 编辑
摘要: ArrayList类是一个特殊的数组。它来自于System.Collections命名空间;通过添加和删除元素,就可以动态改变数组的长度。一、优点1)支持自动改变大小的功能2)可以灵活的插入元素3)可以灵活的删除元素二、局限性跟一般的数组比起来,速度上差些。因为它是动态数组,初始化大小容量4,当数据存满时扩容是以当前数组容量大小的2倍扩容,之后再把数组元素一个一个的存入,数组在扩容时浪费一定的内存空间,和存储时间,而且,元素添加是一个装箱的过程,所以说,跟一般的数组比起来,速度上差些。 三、ArrayList初始化 ArrayList有三种初始化 1)不初始化起容量 ArrayList al 阅读全文
posted @ 2011-07-19 20:29 贺俊峰 阅读(28892) 评论(1) 推荐(1) 编辑
摘要: static void Main(string[] args) { while (true) { Console.WriteLine("输入一串字符"); string str = Console.ReadLine();//定义一个变量str用来存储输入的字符串 int num= Encoding.Default.GetByteCount(str);//Encoding.Default.GetByteCount(str)在系统默认下计算对字符进行编码是所产生的字节数 intlen = str.Length;//获取字符串的长度 Console.WriteLine(" 阅读全文
posted @ 2011-07-19 11:19 贺俊峰 阅读(1603) 评论(0) 推荐(1) 编辑