C# language issue. using and lock statement with multiple items?

  • Thread starter Thread starter Jim S
  • Start date Start date
J

Jim S

My company's code often includes locks, using statements, and
try/catch blocks and ends up with a lot of brackets. Would it make
sense for C# to allow multiple items in these types of blocks?

i.e.

lock (this.var1, this.var2)
{
using (Font font=this.CreateFont(), Brush brush=this.CreateBrush())
{
... do something with font, brush, var1, var2
}
}


Also, has there been talk about allowing a single lock statement to
apply to both the getter and setter of a property?
Maybe like this:
int Value lock(this.val) { get { return this.val; } set { this.val =
value; } }
 
You can do this, which to me is more readable as well

lock (this.var1, this.var2)
{
using (Font font=this.CreateFont())
using(Brush brush=this.CreateBrush())
{
... do something with font, brush, var1, var2
}
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

My company's code often includes locks, using statements, and
try/catch blocks and ends up with a lot of brackets. Would it make
sense for C# to allow multiple items in these types of blocks?

i.e.

lock (this.var1, this.var2)
{
using (Font font=this.CreateFont(), Brush brush=this.CreateBrush())
{
... do something with font, brush, var1, var2
}
}


Also, has there been talk about allowing a single lock statement to
apply to both the getter and setter of a property?
Maybe like this:
int Value lock(this.val) { get { return this.val; } set { this.val =
value; } }

---
 
Back
Top