using (Font font3 = new Font("Arial", 10.0f),
font4 = new Font("Arial", 10.0f))
{
// Use font3 and font4.
}
I know that multiple objects of same type can be used inside a using clause.
Cant i use different types of objects inside the using clause?
Well i tried but although they were different names and different objects, they acted the same = had the same set of methods
Is there any other way to use the using class with different types?
If not, what is the most appropriate way to use it?
using(Font f1 = new Font("Arial",10.0f))
using (Font f2 = new Font("Arial", 10.0f))
using (Stream s = new MemoryStream())
{
}
Like so?
No you can't do it this way, but you can nest
the using
blocks.
using (Font font3 = new Font("Arial", 10.0f))
{
using (Font font4 = new Font("Arial", 10.0f))
{
// Use font3 and font4.
}
}
or as others said, but I'd not recommend it that way because of readability.
using(Font font3 = new Font("Arial", 10.0f))
using(Font font4 = new Font("Arial", 10.0f))
{
// use font3 and font4
}
You can stack using statements to accomplish this:
using(Font font3 = new Font("Arial", 10.0f))
using(Font font4 = new Font("Arial", 10.0f))
{
// use font3 and font4
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With