流用于对IO处理
在System.IO名称空间中有以下类 BinaryReader/Writer TextReader/Writer Stream 其中类Stream为抽象类。由此有三个派生类: MemoryStream:对内存进行读取与写入 BufferedStream:对缓冲器进行读取/写入 FileStream:对文件执行读取与写入 TextReader/Writer为抽象类。由此派生类: StreamReader/StreamWirter StringReader/StreamWriter 需要引入命名空间: using System.IO内存流与缓冲的使用举例: MemoryStream memStream=new MemoryStream(); BufferedStream bufStream=new BufferedStream(memStream); byte[] b=new byte[10]; for(int i=0;i<10;i++) { bufStream.WriteByte((byte)i); } bufStream.Position=0; bufStream.Read(b,0,9); for(int i=0;i<10;i++) { Console.WriteLine("读的值是:{0}",b[i]); } Console.WriteLine("值是:{0}",bufStream.ReadByte()); Console.ReadLine();
文件流的使用 string s=Console.ReadLine(); FileStream fileStream=new FileStream(s,FileMode.OpenOrCreate); BinaryWriter binStream=new BinaryWriter (fileStream); for(int i=1;i<=10;i++) { binStream.Write((int)i); } binStream.Close(); fileStream.Close(); FileStream f=new FileStream(s,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); BinaryReader buf=new BinaryReader(f); for(int i=1;i<10;i++) { Console.WriteLine("输出{0}",buf.ReadByte ()); //在vs2012中这样不能读出东西来Console.WriteLine("输出{0}",Bur.ReadInt32());才行,因为int是32位的}
文本流的使用 string fileName,s; fileName=Console.ReadLine(); StreamWriter fn=new StreamWriter(fileName,true); for(int i=1;i<10;i++) { s=Console.ReadLine(); fn.WriteLine(s); } fn.Close(); StreamReader fr=new StreamReader(fileName); for(int i=1;i<10;i++) { s=fr.ReadLine(); Console.WriteLine(s); } fr.Close(); Console.ReadLine();
C#开发win8.1程序可以利用stackPane实现同一个位置多个控件的交替
private void delete_Click(object sender, RoutedEventArgs e) { database.delete(myCorrectWindows.affair); enter.Visibility = Visibility.Collapsed; cancel.Visibility = Visibility.Collapsed; correct.Visibility = Visibility.Collapsed; delete.Visibility = Visibility.Collapsed; words.Visibility = Visibility.Visible; dragon_image.Visibility = Visibility.Collapsed; correct_window.Children.Clear(); affair_list.Items.Clear(); var items = database.query(myDate.Year, myDate.Month, myDate.Day); foreach (var item in items) { MyItem myItem = new MyItem(item); myItem.DoubleTapped += click_listener; affair_list.Items.Add(myItem); } }
主要是通过设置visibility属性,并且通过数据库查询到控件添加
利用linq对数据库的数据进行排序
private void sort_by_import_Click(object sender, RoutedEventArgs e) { SQLite.TableQueryitems; if (bundle.mode_num == 0) items = database.query(bundle.date.Year); else items = database.query(bundle.date.Year, bundle.date.Month); items = from x in items orderby x.importance select x; affair_list.Items.Clear(); foreach (var item in items) { var temp = new MyItem(item); temp.DoubleTapped += click_to_correct; affair_list.Items.Add(temp); } }