您现在的位置是:主页 > news > wordpress建站系统/江门关键词优化公司

wordpress建站系统/江门关键词优化公司

admin2025/4/26 6:15:07news

简介wordpress建站系统,江门关键词优化公司,做网站营业执照经营范围怎么填写,用什么软件做网站交互效果C#基础 1.注释:单行// 多行/…/ 方法/// 2.访问修饰符 public:成员可以从任何代码访问。 protected:成员只能从派生类访问。 internal:成员只能从同一程序集的内部访问。 protected internal:成员从同一程序集内…

wordpress建站系统,江门关键词优化公司,做网站营业执照经营范围怎么填写,用什么软件做网站交互效果C#基础 1.注释:单行// 多行/…/ 方法/// 2.访问修饰符 public:成员可以从任何代码访问。 protected:成员只能从派生类访问。 internal:成员只能从同一程序集的内部访问。 protected internal:成员从同一程序集内…

C#基础

1.注释:单行// 多行// 方法///

2.访问修饰符
public:成员可以从任何代码访问。
protected:成员只能从派生类访问。
internal:成员只能从同一程序集的内部访问。
protected internal:成员从同一程序集内部或者派生类访问。
private:成员只能在当前类的内部访问。

3.数据类型
值类型(Value types)
c#中有无符号类型,如uint
bool 布尔值
int 32 位有符号整数类型
long 64 位有符号整数类型
byte 8 位无符号整数
float 32 位单精度浮点型
….
enum 枚举
如 enum Days{Monday,Tuesday}
如果强转成int会从0开始,通过赋值可改变数值如enum Days{Monday=1,Tuesday=2}可以配合switch使用
默认是对应int型的,可改变如enum Days:short{Monday,Tuesday}
struct 结构 自定义类型(底层都是struct)如果使用使用class则所有实例都存储在堆栈上

(注,可以直接用值类型调用方法,存储在栈内存上)

引用类型(Reference types)
object 所有类型的基类
string
用==比较,(运算符重载)
s[1],根据下标获取某一个字符
加上@之后,不会进行转义如 String s=@”c:\aa.txt”; 等价于 s=”c:\aa.txt”
StringBuilder AppendFormat(“hello{0}{1}”,”word”,”!!!!”);第一个参数是格式,{0}传参,后面是参数

dynamic(类型检查在运行阶段)
指针类型(Pointer types)

类型推断:使用var 关键字,编译器可以推断出类型
可为空类型
int? isnu=100;等价于System.Nullable isnu=100;

3.表达式

4.流程控制
跳转语句 goto 标识符,跳转到程序中用标签指定的另一行
goto labell;

labell:

循环 foreach 用in代替java的:如
foreach(var tem in array){…}
跳出循环:break;
跳过一次循环:continue

5.关键字
abstract是关键字
@abstract 标识符

6.对象和类型
属性
public int Age{
get{return age+10};
set;
}
实体类中的属性直接写成

 public int Age{get;set;}

常量声明使用const关键字相当于java的static final
public const string One=”1”
传参—默认都是通过值传递,即传递一个变量的副本,方法退出后,对变量的修改会丢失。
使用ref关键字,可以强制使用引用传递如 ,但是所有的引用都需要初始化值
void fun(ref int i){
i=10;
}
这样会影响原来的值
*使用out 关键字,这样可以不用初始化,调用方法时,可以返回多个值
只读字段 readonly
get set方法 public string name{get;set}

7.关于System.Object的一些方法
ToString() 将对象转化为字符串

8.继承
使用: 表示继承extends
把一个基类函数声明为virtual,就可以重写了.字段也可以,虚方法
public class MyC : MyA,MyB{
}
base关键字对应–java的super
抽象类 abstract 可以被继承
终类:使用sealed关键字,—–类似java的final
与java一样单继承,多实现
接口与java一样

  抽象类:abstract关键字接口: interface(不能有字段,所有的方法都是抽象的)如果是继承实现抽象的方法加上override关键字 public override int geti(){return 2;}如果是实现接口,实现接口中的方法,不用加该关键字

9.异常
C# 中的异常类主要是直接或间接地派生于 System.Exception
用户自定义的异常类是派生自 ApplicationException 类

10.类型转换。关于强转,如果是引用或非空类型可以使用as关键字如
int—string i.ToString();
string—int Convert.ToInt32(“100”)或Int32.Parse(“100”);或者int n; bool s=Int32TryParse(“100”,out n);会返回布尔型,转换蔡成功n=100,s=ture否则n=0,s=false
装箱—值类型转换为引用类型,int i=100; object oi=i;
拆箱- int j=(int)oi

11.集合

链表:List ArrayLiat 键值对:Hashtable  m.Add("name","jock");m["name"]Dictionary 如果获取一个不存在的key会报错ConcurrentDictionary 线程安全的SortedList 会根据key值排序//继承父类方法加上virtual之后,可以被重写,重写的方法加上override关键字;如果不重写,但又同名,使用new关键字。//如果不希望被继承,使用sealed关键字-----相当于final//实例化过程,与java类似/*//一维数组值int[] n = new int[5];int[] n1 = { 1,2,3,4,5};n[0] = 1;//二维数组string[,] n2 = new String[5, 4];n2[0, 0] = "1";//数组的数组,有一个维度长度不固定,初始化指定int[][] n3= new int[2][];int[][] n4 = { new int[] { 1, 2, 4 }, new int[] { 1, 3 } };n3[0] = new int[6];n3[1] = new int[2];n3[2] = new int[4];n3[0][0] = 3;#region 3.集合ArrayList al = new ArrayList();al.Add(4);Hashtable m = new Hashtable();m.Add("name","jock");Console.WriteLine(m["name"]);Dictionary<String, String> m1 = new Dictionary<String, String>();

12.IO
、、、、、、、、、、、、、、、、、、、、、、、、

   //遍历目录//File 静态的方法,FileInfo需要实例化调用方法//文件是否存在 File.Exists(@"path");DirectoryInfo dir = new DirectoryInfo(@"F:\");foreach (FileInfo f in dir.GetFiles("*.exe")) {String n=f.Name;//文件名long size = f.Length;//大小DateTime creattime = f.CreationTime;//创建时间Console.WriteLine(n + ""+size);}
、、、、、、、、、、、、、、、、、、、、、、、//新建文件并写入内容class Program {private const string FILE_NAME = @"F:\a.txt";public static void Main(string[] args){ if (File.Exists(FILE_NAME)) {//若存在则返回return;}FileStream fs = new FileStream(FILE_NAME,FileMode.Create);BinaryWriter w = new BinaryWriter(fs);w.Write("aaa");w.Close();fs.Close();}}
。。。。。。。。。。。。。。。。。。。。。。。
//向现有文件添加内容,,使用using 关键字,使用完就会释放。io读写,数据库连接时使用class Program {private const string FILE_NAME = @"F:\a.txt";public static void Main(string[] args){using (StreamWriter w=File.AppendText(FILE_NAME)) {log("this is a waring",w);w.Close();}}public static void log(string log,TextWriter w) {w.WriteLine(DateTime.Now + ":message:"+log);w.Flush();}}
。。。。。。。。。。。。。。。。。。。。。。。
//FileStream 读文件class Program {private const string FILE_NAME = @"F:\a.txt";public static void Main(string[] args){if (!File.Exists(FILE_NAME)){//若不存在则返回return;}FileStream fs = new FileStream(FILE_NAME, FileMode.Open,FileAccess.Read);BinaryReader r = new BinaryReader(fs);for (int i=0;i<5;i++) {Console.WriteLine(r.ReadString());}r.Close();fs.Close();Console.ReadKey();}}
;;;;;;;;;;;;;;;;;;;;;;;
//读文件 StreamReader 
class Program{private const string FILE_NAME = @"F:\a.txt";public static void Main(string[] args){if (!File.Exists(FILE_NAME)){//若不存在则返回return;}using (StreamReader sr=File.OpenText(FILE_NAME)) {String input;while ((input=sr.ReadLine())!=null) {Console.WriteLine(input);}sr.Close();}           Console.ReadKey();}}

///时间与日期
//DateTime 几乎可以获取时间相关的所有信息
//TimeSpan  表示时间段 可应用于时间运算static void DateAndTime(){///获取当前时间2017/12/5 21:10:43DateTime dt = DateTime.Now;Console.WriteLine(dt+"b");///日期格式化,参数为你想要的格式string d1 = dt.ToString("yyyy-mm-dd");Console.WriteLine(d1);///获取毫秒数,只能根据当前时间-1970/01/01的毫秒时间差TimeSpan ts = DateTime.Now - DateTime.Parse("1970-1-1");long l = (long)ts.TotalMilliseconds;Console.WriteLine(l);///}