1:Unicode 转义字符使用
Console.WriteLine(@"C:\TEMP\MyDir\MyFile.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));
本文介绍了C#中Unicode转义字符的使用方法,使路径字符串更易读;同时展示了如何在WPF应用中动态加载图片,包括生成随机数选择图片和设置图片源的详细步骤。
2217

被折叠的 条评论
为什么被折叠?



