04protected访问修饰符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _04protected访问修饰符
{
class Program
{
static void Main(string[] args)
{
//public private
Person p = new Person();
}
}
public class Person
{
protected string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
public class Student : Person
{
public void Test()
{
}
}
}
05ArrayList集合
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _05ArrayList集合
{
class Program
{
static void Main(string[] args)
{
//创建了一个集合对象
ArrayList list = new ArrayList();
//集合:很多数据的一个集合
//数组:长度不可变、类型单一
//集合的好处:长度可以任意改变 类型随便
list.Add(1);
list.Add(3.14);
list.Add(true);
list.Add("张三");
list.Add('男');
list.Add(5000m);
list.Add(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
Person p = new Person();
list.Add(p);
list.Add(list);
//list.AddRange(new string[]{})
for (int i = 0; i < list.Count; i++)
{
if (list[i] is Person)
{
((Person)list[i]).SayHello();
}
else if (list[i] is int[])
{
for (int j = 0; j < ((int[])list[i]).Length; j++)
{
Console.WriteLine(((int[])list[i])[j]);
}
}
else
{
Console.WriteLine(list[i]);
}
//Console.WriteLine(list[i]);
}
Console.ReadKey();
}
}
public class Person
{
public void SayHello()
{
Console.WriteLine("我是人类");
}
}
}
06ToString的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _06ToString的问题
{
class Program
{
static void Main(string[] args)
{
//我们将一个对象输出到控制台 默认情况下 打印的就是这个对象所在的类的命名空间
int[] nums = { 1, 2, 3, 4, 5 };
Console.WriteLine(nums.ToString());
Person p = new Person();
Console.WriteLine(p.ToString());
Console.ReadKey();
}
}
public class Person
{
public void SayHello()
{
Console.WriteLine("我是人类");
}
}
}
07ArrayList的各种方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace _07ArrayList的各种方法
{
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
//添加单个元素
list.Add(true);
list.Add(1);
list.Add("张三");
//添加集合元素
list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
//list.AddRange(list);
//list.Clear();清空所有元素
//list.Remove(true);删除单个元素 写谁就删谁
//list.RemoveAt(0);根据下标去删除元素
//list.RemoveRange(0, 3);根据下标去移除一定范围的元素
// list.Sort();//升序排列
//list.Reverse();反转
//list.Insert(1, "插入的");在指定的位置插入一个元素
//list.InsertRange(0, new string[] { "张三", "李四" });在指定的位置插入一个集合
//bool b = list.Contains(1);判断是否包含某个指定的元素
list.Add("颜世伟");
if (!list.Contains("颜世伟"))
{
list.Add("颜世伟");
}
else
{
Console.WriteLine("已经有这个屌丝啦");
}
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine(list[i]);
}
Console.ReadKey();
}
}
}
08ArrayList集合长度的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace _08ArrayList集合长度的问题
{
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
list.Add(1);
list.Add(1);
list.Add(1);
list.Add(1);
list.Add(1);
list.Add(1);
list.Add(1);
list.Add(1);
list.Add(1);
Console.WriteLine(list.Count);
Console.WriteLine(list.Capacity);
Console.ReadKey();
//count 表示这个集合中实际包含的元素的个数
//capcity 表示这个集合中可以包含的元素的个数
}
}
}
09集合的练习
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _09集合的练习
{
class Program
{
static void Main(string[] args)
{
//创建一个集合,里面添加一些数字,求平均值与和,最大值,最小值
//ArrayList list = new ArrayList();
//list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
//int sum = 0;
//int max = (int)list[0];
//for (int i = 0; i < list.Count; i++)
//{
// if ((int)list[i] > max)
// {
// max = (int)list[i];
// }
// sum += (int)list[i];
//}
//Console.WriteLine(sum);
//Console.WriteLine(max);
//Console.WriteLine(sum/list.Count);
//Console.ReadKey();
//写一个长度为10的集合,要求在里面随机地存放10个数字(0-9),
//但是要求所有的数字不重复
//ArrayList list = new ArrayList();
//Random r = new Random();
//for (int i = 0; i <10; i++)
//{
// int rNumber = r.Next(0, 10);
// //集合中没有这个随机数
// if (!list.Contains(rNumber))
// {
// list.Add(rNumber);
// }
// else//集合中有这个随机数
// {
// //一旦产生了重复的随机数 这次循环就不算数
// i--;
// }
//}
//for (int i = 0; i < list.Count; i++)
//{
// Console.WriteLine(list[i]);
//}
//Console.ReadKey();
string str = "2++b/c*d/e";
string[] strNew = str.Split(new char[] { '+', '-', '*', '/' });
StringBuilder sb = new StringBuilder();//capcity count
sb.Append("12312312312312312");
Console.WriteLine(sb.Capacity);
//char[] chs= {'1','2','3'};
Console.ReadKey();
}
}
}