| WPF-Question-Answers-31-40 | C# Question Answers-11 - 20 | |
C# (C-Sharp) Question Answers - 1 - 10 |
Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.
Font font = new Font("Arial", 10.0f)
using (font)
{
// use font here
}
Yes, we can use the object declared and instantiated before the using statement.
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.
No. Once the proper catch block is processed, control is transferred to the finally block (if there are any).
Yes, we can use multiple Catch clause in try statement.
Yes. Just leave the class public and make the method sealed.
No, you can’t — the signature of the virtual method must remain the same; only the keyword virtual is changed to the keyword override.
Yes. .NET does support multiple interfaces.
Examples:
// This class is immutable. After an object is created,
// it cannot be modified from outside the class. It uses a
// constructor to initialize its properties.
class Contact
{
// Read-only properties.
public string Name { get; }
public string Address { get; private set; }
// Public constructor.
public Contact(string contactName, string contactAddress)
{
Name = contactName;
Address = contactAddress;
}
}
// This class is immutable. After an object is created,
// it cannot be modified from outside the class. It uses a
// static method and private constructor to initialize its properties.
public class Contact2
{
// Read-only properties.
public string Name { get; private set; }
public string Address { get; }
// Private constructor.
private Contact2(string contactName, string contactAddress)
{
Name = contactName;
Address = contactAddress;
}
// Public factory method.
public static Contact2 CreateContact(string name, string address)
{
return new Contact2(name, address);
}
}
Yes. The keyword sealed will prevent the class from being inherited.
| WPF-Question-Answers-31-40 | C# Question Answers-11 - 20 | |