elec60
دوشنبه 07 مهر 1393, 12:09 عصر
$ Sign
هدف از $ ساده تركردن دسترسي به عناصر رشته است:
var col = new Dictionary<string, string>()
{
// using inside the intializer
$first = "Hashem"
};
//Assign value to member
//the old way:
col["first"] = "Hashem";
// the new way
col.$first = "Hashem";
Exception Filters
اين ويژگي در VB وجود داشت و هم اكنون به سي شارپ هم اضافه شده است. اين ويژگي امكان آن را فراهم مي كند كه بلوك catch شرطي داشته باشيم:
try { throw new Exception("Me"); } catch (Exception ex) if (ex.Message == "You") { // this one will not execute. } catch (Exception ex) if (ex.Message == "Me") { // this one will execute }
await in catch and finally block
معلوم نيست چرا مايكروسافت اين ويژگي رو با معرفي await و async در C# 5.0 اضافه نكرده بود!
اگر بخواهيم از جزئيات خطا در بلوك catch لاگ بگيريم و در فايل ذخيره كنيم اين كار مستلزم انجام عمليات I/O خواهد بود و براي I/O Bound Operation بهتره از روشهاي آسنكرون استفاده كنيم:
try { DoSomething(); } catch (Exception) { await LogService.LogAsync(ex); }
هدف از $ ساده تركردن دسترسي به عناصر رشته است:
var col = new Dictionary<string, string>()
{
// using inside the intializer
$first = "Hashem"
};
//Assign value to member
//the old way:
col["first"] = "Hashem";
// the new way
col.$first = "Hashem";
Exception Filters
اين ويژگي در VB وجود داشت و هم اكنون به سي شارپ هم اضافه شده است. اين ويژگي امكان آن را فراهم مي كند كه بلوك catch شرطي داشته باشيم:
try { throw new Exception("Me"); } catch (Exception ex) if (ex.Message == "You") { // this one will not execute. } catch (Exception ex) if (ex.Message == "Me") { // this one will execute }
await in catch and finally block
معلوم نيست چرا مايكروسافت اين ويژگي رو با معرفي await و async در C# 5.0 اضافه نكرده بود!
اگر بخواهيم از جزئيات خطا در بلوك catch لاگ بگيريم و در فايل ذخيره كنيم اين كار مستلزم انجام عمليات I/O خواهد بود و براي I/O Bound Operation بهتره از روشهاي آسنكرون استفاده كنيم:
try { DoSomething(); } catch (Exception) { await LogService.LogAsync(ex); }