您的位置:首页 > 编程语言 > C#

10个C#编程和Visual Studio使用技巧

2010-10-27 10:49 901 查看
介绍10个C#编程和Visual Studio IDE使用技巧。

1、Environment.Newline

你是否知道这个属性是与平台无关的?允许你根据每个平台输出新的换行字符。

Console.WriteLine("My Tips On ,{0}C#", Environment.NewLine);

2、命名空间别名

你是否知道可以使用更短的别名代替长的命名空间?你是否遇到过需要限制完整的命名空间以避免产生歧义?看下面的代码示例,它是使用扩展的.NET Framework控件创建的一个通用库。

寻找恐怖的数据集合并错误根本原因

StringBuilder error Messages =new StringBuilder();
try
{
DataSet dataSet1 = populateDataSet(1);
DataSet dataSet2 = populateDataSet(2);

dataset1.Merge(dataset2);
}
catch (System.Data.DataException de)
{
foreach (DataTable myTable in dataSet1.Tables)
{
foreach (DataRow myRow in myTable.GetErrors())
{
foreach (DataColumn myColumn in myRow.GetColumnsInError())
{
//loop through each column in the row that has caused the error
//during the bind and show it.
error Messages .Append(string.Format(
"Merge failed due to : {0}", myColumn.GetColumnError(myColumn)));
}
}
}
}

小结

希望你能灵活运用这些C#编程和Visual Studio技巧,享受写代码的乐趣,如果你有其它技巧愿意和大家分享,欢迎在本文后面发表评论。

转自:互联网

本文地址:/article/4961804.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: