访问和设置
访问和设置
public void Run(){
}
public void Stop(){
}
public float length(){
}
创建对象
结构体不需要new
类需要new
模块化编程
try{里面放可能出错的代码}
catch(FormatException e)
{
console.writeLine("")
n1 = convert.toint32(console.readline)
n2 = convert.toint32(console.readline)
}
逐语句
逐断dian
每一个类都是使用单独的文件来保存的
class MyList<T>
{
private T[] data = new T[0]; //data null
//引用类型 new
//MyClass mc;
}
class ClassA<T>
{
private T a;
private T b;
public ClassA(T a , T b)
{
this.a = a;
this.b = b;
}
public string GetSum()
{
dynamic num1 = a;
dynamic num2 = b;
}
}
class Program
{
static void ShowList(List<int> list)
{
foreach (int temp in list)
{
Console.Write(temp + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
List<int> list = new List<int>() { 56, 23, 894, 32, 5623, 32,4573 };
//Console.WriteLine(list.Capacity);
//list.Add(800);
//Console.WriteLine(list[2]);
//list.Insert(3, 800);
//list.Remove(32);
//ShowList(list);
//list.RemoveAt(2);
//ShowList(list);
//增 删 改 查
//Console.WriteLine(list.IndexOf(320));
//Console.WriteLine(list.LastIndexOf(32));
list.Sort();
ShowList(list);
}
}
class Program
{
static viod Main(string[] args)
{
List<int> list = new List<int>() {321,654 987};
list.Add(900);
list.Add(6732);
Console.Writeline(list[3]);
list.Count;
}
}
class Program
{
static void Main(string[] args)
{
StudentSt stu1 = new StudentSt(18, "小芳");
StudentSt stu2 = new StudentSt(25, "小刚");
stu2 = stu1;
stu1.age = 30;
stu1.name = "费伦";
Console.WriteLine(stu2.age);
Console.WriteLine(stu2.name);
}
}
struct StudentSt
{
public int age;
public string name;
public StudentSt(int age,string name)
{
this.age = age;
this.name = name;
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace _09_抽象类
{
public abstract class Enemy
{
private int hp;
private int speed;
public void Move()
{
Console.WriteLine("Move");
}
public abstract void Attack();
}
}
1、编写健壮性强的代码
https://blog.csdn.net/zcaixzy5211314/
public T this[int index]{
get{
if(index<0 || index > count -1){
throw new Argumentout0fRangeException("参数超出范围了");
}
return data[index];
}
//添加元素之前,先判断数组是否已经满 if (data.Length==count) { T[] temp = new T[count * 2]; for(int i =0; i< data.Length; i+){ temp[i]= data[i]; } data = temp; } data[count] = item;
int [] myArr = {1,2,3,4};
try{
int temp = myArr[4];
}
catch (Index0utOfRangeException e){
//出现这个异常的时候,怎么处理
Console.WriteLine("出现了数组下标越界的异常");
}
catch (FieldAccessException e){
Console.WriteLine("出现 FieldAccessException的异常");
}
finally{
Console.WriteLine(""不管是否出现异常,都会执行");
)
p
1a
2b
3b
4c
5
6c