C#学习心得1

1:Unicode 转义字符使用

  

      Console.WriteLine(@"C:TEMPMyDirMyFile.doc");   //等价于下面的

      Console.WriteLine("C:\TEMP\MyDir\MyFile.doc");

 在Windows中寻找目录很实用,写出来的代码更容易读懂.

2:   Image控件动态加载图片   C#  WPF中可这样用。

 Image img = new Image();
 int num = rand.Next(1, 10); //产生1到9的随机数
 string filename = "Images/" + num + ".png";
 //为图片的source赋值
 img.Source = new BitmapImage(new Uri(filename, UriKind.Relative));
Image img = new Image();
int num = rand.Next(1, 10); //产生1到9的随机数
string filename = "pack://application:,,,/Images/" + num + ".png";
//为图片的source赋值
img.Source = new BitmapImage(new Uri(filename));
原文地址:https://www.cnblogs.com/Mckk/p/4265776.html