C#笔记--04--常用类


一:String

C#笔记--04--常用类_第1张图片

C#笔记--04--常用类_第2张图片

二:数组

实际开发中,一般方法或API等使用的是数组作为规范,但实际的使用都是使用集合

    ->List<T>  线性集合,长度可变的数组

            ->增    Add()   AddRange()

            ->删    Remove( T )   RemoveAt( int )

            ->改    可以像数组一样修改 //list[9] = '123';

            ->查    bool Contains( T )

                        IndexOf()

             -> 遍历 for

                            foreach(类型 临时变量 in 集合)

                            {

                                    //使用临时变量进行处理

                            }

    ->Dictionary< TKey , TValue > 散列集合

            ->键值对

                ->为什么要使用这个集合: 为了快速查找

            ->常用方法   

                ->增     Add(键,值)

                ->删     RemoveKey

                ->改     索引   dic["dictonary"] = "词典";

                ->查     索引

                            ContainsKey

               ->遍历(不常用)

三:文件操作

      -> 文件是什么?

            ->windows 环境下文本文件基本格式

                    ->字符集历史:ascii ->双字节 ->unicode(utf-16) ->utf-8

                    ->ANSI (和操作系统有关)   encodeing.defaut 用的就是这个

                    ->unicode

                            ->unicode

                            ->unicode big endim

                            ->utf-8

            ->如何操作 

                        -> 用什么类能做什么东西

                        -> 命名空间: System.IO; // input output

                        -> FileStream 文件流, 将文件以字节的方式进行读写

                                ->构造方法:  new FileStream(文件路径,FileMode, FileAccess);  

                                        FileMode: Create , CreateNew,Append, Open           

                                -> 读写方法:

                                        -> int Readbyte();      void Writebyte(byte);

                                        -> int Read( byte[] buffer, int offset,int count);

                                                void Write(byte[] buffer,int offset,int count);

                                        ->了解

                                                -> void Flush(); //清空缓存,写入硬盘

                                                ->void Dispose();// 清空非托管资源

                                                ->Position 属性 //文件处理,指针与文本文件书写一样是有位置的

                            -> StreamReader 与 StreamWriter  专门针对文本文件的读写操作

                                    ->读流    

                                            new StreamReader(文件路径,Encoding);

                                    ->写流

                                            new  StreamWriter(文件路径,bool isAppend, Encoding);

                                    -> 读的方法

                                            string  ReadLine(); //读取文件中的一行

                                            string ReadToEnd() ; //读取所有的内容

                                     ->写的方法

                                            void Write(...);  //写入内容

                                            void WriteLine(...); //吸入一行文本

                                ->File 静态类

                                        AppendAllText

                                        AppendAllLines

                                        ReadAllText

                                        ReadAllLines

                                        WriteAllText

                                        WriteAllLines

                                        bool Exist(); //文件是否存在

                                   ->Directory 静态类

                                        string[]  GetFiles();  //返回指定路径下的所有文件

                                        string[]  GetDirectories(string);// 返回路径下面所有的文件夹

                                        bool  Exist(); //路径是否存在

                                    ->Path 处理路径

                                    获得后缀名

                                    获得文件名  GetFileName

                                    或者没有后缀的文件名  GetFileNameWithoutExtension

                                    获得全路径  string GetFullPath(string);

                                    -> FileInfo  DirectoryInfo  DriverInfo  静态类


你可能感兴趣的:(C#笔记--04--常用类)