规则:
1. 方法命名是用帕斯卡
2. 变量使用驼峰
3. is开头的都是bool I开头的都是接口 abs开头的是抽象类
4. 弄一个变量在这里必须赋初值
***char.IsDigit: 判断该char是否是10进制数值 ***
string.Format():字符串格式化
字符串 --> 特殊的字符数组, 有下标 能遍历但是不能改
字符串
1. 比较字符串(忽略大小写)
2. 比较字符串(不忽略大小写)
3. 分割字符串
4. 查找字符串
5. 替换字符串 都换
6. 截取字符串
str.Trim() --> 去掉字符串前后空格
Substring(index, count) --> 截取之后的字符串
Substring(index) --> 截取之后的字符串
namespace 截取字符串
{
class Program
{
static void Main(string[] args)
{
string str = "你好世界,呵呵哒";
//string newStr = str.Substring(0, 3);
string newStr = str.Substring(5);
Console.WriteLine(newStr);
}
}
}
Replace(old,new) 都换
namespace 替换字符串
{
class Program
{
static void Main(string[] args)
{
string str = "呵呵哒,呵呵哒你好世界,呵呵哒";
string newStr = str.Replace("呵呵哒", "C# 编程");
Console.WriteLine(newStr);
}
}
}
indexof/lastindexof 返回其所在下标位置 若-1 就代表该字符串没有对应namespace 查找
{
class Program
{
static void Main(string[] args)
{
string str = “C#编程我喜欢,C#编程我呵呵哒C#”;
// int tmpIndex = str.IndexOf(“C#”);
int tmpIndex = str.LastIndexOf("C# ");
Console.WriteLine(tmpIndex);
}
}
}it(char/char[]) 按照char/char[] 进行分割, 返回一个字符串数组
namespace 字符串分割
{
class Program
{
static void Main(string[] args)
{
string stuInfo = "张三-男[email protected]";
string[] infos = stuInfo.Split('-');
Console.WriteLine(infos.Length);
//以'-'为分割点分割字符串
Console.WriteLine("===================");
foreach (string s in infos)
{
Console.WriteLine(s);
}
}
}
}
Compare: 0代表相等 非0 代表不相等 (strA,StrB, true) 忽略大小写
namespace 字符串比较
{
class Program
{
static void Main(string[] args)
{
string str01 = "ABC";
string str02 = "ABc";
// Console.WriteLine(str02.Equals(str02));
//返回为0 代表 01 == 02 true 代表忽略大小写
int tmpInt = string.Compare(str01, str02, true);
Console.WriteLine(tmpInt);
}
}
}
Equals true 代表相等 不忽略大小写
string.IsNullOrEmpty(str) 判断str是否是空对象或者是empty
out: 传出参数,在方法内部必须赋值
ref: 传入参数,在方法外部必须赋值
OOP编程
子类调用父类方法应该在方法中调用
对象是一个抽象概念, 用代码表示就是new出来的基本都是对象
在unity中最能体现OOP三大特性中的哪一个?
*继承 封装 多态
命名空间就是包含功能类似的class的一个集合
public: 对象和子类都能访问
protected:子类可以访问,子类对象不能访问
private: 对象和子类都不能访问
base: 就是访问父类成员(公开和保护的)
封装:
私有
private int _age;
public int age;
get{return_age};
set{_age=value};
多态的目的
父类控制子(抽象类 虚方法 接口都是为了实现多态)