Posts
.NET 4.0 New Feature - Environment.SpecialFolder
CDBurning C:\Documents and Settings[User Account]\Local Settings\Application Data\Microsoft\C D Burning
CommonAdminTools C:\Documents and Settings\All Users\「開始」功能表\程式集\系統管理工具
CommonDocuments C:\Documents and Settings\All Users\Documents
CommonMusic C:\Documents and Settings\All Users\Documents\My Music
CommonOemLinks
CommonPictures C:\Documents and Settings\All Users\Documents\My Pictures
CommonStartMenu C:\Documents and Settings\All Users\「開始」功能表
CommonPrograms C:\Documents and Settings\All Users\「開始」功能表\程式集
CommonStartup C:\Documents and Settings\All Users\「開始」功能表\程式集\啟動
CommonDesktopDirectory C:\Documents and Settings\All Users\桌面
CommonTemplates C:\Documents and Settings\All Users\Templates
CommonVideos C:\Documents and Settings\All Users\Documents\My Videos
Fonts C:\WINDOWS\Fonts
MyVideos
NetworkShortcuts C:\Documents and Settings[User Account]\NetHood
read morePosts
.NET 4.0 New Feature - Environment.FailFast
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { try { Environment.FailFast(“A castrophic failure has occured.”, new DivideByZeroException ()); } catch (Exception) { Console.WriteLine(“catch…”); } finally { Console.WriteLine(“finally…”); } } } }
read morePosts
.NET 4.0 New Feature - System.Runtime.Caching
namespace CacheItemPolicyDemo { class Program { static void Main(string[] args) { ContentProvider textFile = new ContentProvider(); Stopwatch sw = new Stopwatch(); while (true) { sw.Reset(); sw.Start(); Console.WriteLine(DateTime.Now.ToString()); Console.WriteLine(textFile.Content); sw.Stop(); Console.WriteLine(“Elapsed Time: {0} ms”, sw.ElapsedMilliseconds); Console.WriteLine(new string(’=’, 50)); Console.ReadLine(); } } }
public class ContentProvider { public String Content { get { const string CACHE_KEY = "Content"; string content = m_Cache[CACHE_KEY] as string; if (content == null) { CacheItemPolicy policy = new CacheItemPolicy(); policy.
read morePosts
PermissionController權限管理類別
#Region “Var” Private _allPermission As T Private _permission As T #End Region
#Region “Public Property” Public Property AllPermission() As T Get Return _allPermission End Get Private Set(ByVal value As T) _allPermission = value End Set End Property
''' <summary> ''' Gets the permission. ''' </summary> ''' <value>The permission.</value> Public Property Permission() As T Get Return _permission End Get Private Set(ByVal value As T) _permission = value End Set End Property #End Region
read morePosts
.NET 4.0 New Feature - Stream.CopyTo
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { using (MemoryStream sourceStream = new MemoryStream(512)) { using (StreamWriter sw = new StreamWriter(sourceStream)) { sw.WriteLine(“Test Stream.CopyTo”); sw.Flush();
sourceStream.Seek(0, SeekOrigin.Begin); using (FileStream targetStream = new FileStream("Test.Txt", FileMode.Create)) { sourceStream.CopyTo(targetStream); } } } } } }
read morePosts
.NET 4.0 New Feature - String.Concat
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String[] stringCollection = { “123”, “456”, “789” }; int[] intCollection = { 123, 456, 789 }; Object[] objCollection = { 123, “456”, 789.0f }; float[] floatCollection = { 123.0f, 456.0f, 789.0f };
ShowValue<String>("stringCollection", stringCollection); ShowValue<int>("intCollection", intCollection); ShowValue<Object>("objCollection", objCollection); ShowValue<float>("floatCollection", floatCollection); } static void ShowValue<T>(string title, IEnumerable<T> values) { Console.WriteLine("{0}: {1}", title, string.Concat<T>(values)); } } }
read morePosts
.NET 4.0 New Feature - String.IsNullOrWhiteSpace
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] values = { null, String.Empty, “ABCDE”, new String(’ ‘, 20), " “, new String(’\u2000’, 10), };
Console.WriteLine(new String('=', 50)); Console.WriteLine("IsNullOrWhiteSpaceDemo..."); IsNullOrWhiteSpaceDemo(values); Console.WriteLine(new String('=', 50)); Console.WriteLine("MSDNCustomIsNullOrWhiteSpaceDemo..."); MSDNCustomIsNullOrWhiteSpaceDemo(values); Console.WriteLine(new String('=', 50)); Console.WriteLine("CustomIsNullOrWhiteSpaceDemo..."); CustomIsNullOrWhiteSpaceDemo(values); } public static void IsNullOrWhiteSpaceDemo(string[] values) { foreach (string value in values) Console.WriteLine("String.IsNullOrWhiteSpace({0}): {1}", value, String.IsNullOrWhiteSpace(value)); } public static void MSDNCustomIsNullOrWhiteSpaceDemo(string[] values) { foreach (string value in values) Console.
read morePosts
.NET 4.0 New Feature - String.Join
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String[] stringCollection = { “123”, “456”, “789” }; int[] intCollection = { 123, 456, 789 }; Object[] objCollection = { 123, “456”, 789.0f }; float[] floatCollection = { 123.0f, 456.0f, 789.0f };
ShowValue<String>("stringCollection", stringCollection); ShowValue<int>("intCollection", intCollection); ShowValue<Object>("objCollection", objCollection); ShowValue<float>("floatCollection", floatCollection); } static void ShowValue<T>(string title, IEnumerable<T> values) { Console.WriteLine("{0}: {1}", title, string.Join(",", values)); } } }
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String[] stringCollection = { “123”, “456”, “789” }; int[] intCollection = { 123, 456, 789 }; Object[] objCollection = { 123, “456”, 789.
read morePosts
.NET 4.0 New Feature - Tuple
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var var1 = Tuple.Create(1, 2, 1); var var2 = Tuple.Create(1, 1, 2);
Console.WriteLine("Var1 : {0}", var1); Console.WriteLine("Var2 : {0}", var2); Console.WriteLine("Var1 == Var2 : {0}", var1 == var2); Console.WriteLine("Var1.Equals(Var2) : {0}", var1.Equals(var2)); Console.WriteLine("(Var1 as IComparable).CompareTo(Var2) : {0}", (var1 as IComparable).CompareTo(var2)); Console.WriteLine(); Console.WriteLine("Original Array..."); var tupeArray = new Tuple<int, int, int>[] { var1, var2 }; foreach (var item in tupeArray) Console.
read morePosts
使用C#呼叫VB.NET的CallByName函式
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataTable dt = new DataTable(); … foreach (DataRow dr in dt.Rows) { foreach (DataColumn dc in dt.Columns) { Versioned.CallByName(obj, dc.ColumnName, CallType.Set, dr(dc.ColumnName)); } } } } }
read more