Using syntactic sugar / inline functionality

I was busy deeper in things like multithreading and deadlock, etc. The book was intended for both pseudo-code and C code, and I was busy looking for implementations of things like Mutex locks and monitors.

It reminded the following: in C # and in fact .NET, we have a lot of syntactic sugar in order to do something. For example (.NET 3.5):

lock(obj)
{
   body
}

Equally:

var temp = obj;

Monitor.Enter(temp);

try 
{ 
   body 
}
finally 
{ 
   Monitor.Exit(temp); 
}

, using() {} .. , " " , " " ? - , , , ?

, Process using, . - , .

,

+3
4

. , , , , - .

- (, IEnumerator<T> foreach), , . , - .

+12

- , , , ( , , perf ). , , , , .

+7

# linq:

var filteredCities =
    from city in cities
    where city.StartsWith("L") && city.Length < 15
    orderby city
    select city;

- ( ):

var filteredCities =
  cities.Where(c => c.StartsWith("L") && c.Length < 15))
    .OrderBy(c => c)
    .Select(c => c); 

#, , ; , .

, , , .

+2

using - , .NET Framework. , IDisposable .

, , - , . , , using, , .

, , - , , - - , .

Edit:

I thought about it, and I decided that I thought usingit was just a misleading keyword that you chose. foreachdoes exactly what it sounds, while it usingdoes not mean to me what is really happening. Anyone have any thoughts on this? What if they had a keyword disposing; do you think it would be better?

+1
source

Source: https://habr.com/ru/post/1745399/


All Articles