Professional Documents
Culture Documents
Faq 68
Faq 68
Table of Contents
S# Question
1. What happens when we instantiate a struct without the new keyword?
2. Do delegates really provide type safety?
3. How is the == operator different from object.Equals()?
4. Why should we provide a property for a private field and write set and get
accessors when it is easier to simply declare the field as public?
5. What is the use of the /target: command line option?
6. How can we create a constant that is an array?
7. What version of .NET should be used to use generics?
8. How can an array be resized?
9. How is const different from static readonly?
10. How can a destructor be made virtual?
11. Can two arrays be concatenated?
12. Why should the Main() method be declared as static?
13. Is it possible to declare the override method as static when the original
method is non-static?
14. Can enums, structs, or sealed classes be used as generic constraints?
15. How is a struct different from a class?
16. Does C# consist of an in-built class library?
17. Can the get and set accessors of a property have different access
modifiers?
18. In an inheritance hierarchy, the destructors of which class are called first?
19. What happens if I catch an exception but do not write any code inside the
catch block to handle the exception?
20. Why are data members of the Hashtable class stored using the private
access modifier?
21. How is the System.Array.CopyTo() method different from the
System.Array.Clone() method?
22. If varOne.Equals(varTwo) returns true, does it imply that
varOne.GetHashcode will return the same hash code as
varTwo.GetHashcode?
23. Is it possible for the compiler to execute multiple catch blocks for a single
try block?
© Aptech Ltd Version 1.0 Page 2 of 17
Essentials of C# Programming FAQ
24. How is the ref modifier different from the out modifier?
25. What is the difference between managed and unmanaged code?
26. What is an assembly?
27. Can the scope of a field or method of a class to the classes in the same
namespace be restricted?
28. How can we create a DLL in C#?
29. If the Console.WriteLine() method encounters a NULL character within a
string, will it stop printing the output?
30. What is the GAC? Why is it used?
31. Can an async method have multiple await operators?
32. Where can we configure the endpoint address of a WCF service?
33. In cryptography, what is hashing?
34. What factors should we consider before selecting either symmetric or
asymmetric encryption to encrypt data?
35. Which .NET Framework version comes with Visual Studio 2017?
54. What are the new tools in Debugger environment in Visual Studio 2017?
55. How to set a breakpoint in the debugger tool?
56. What is the use of a Data Tip?
57. How can a package be reused by developers?
Why should we provide a property for a private field and write set
and get accessors when it is easier to simply declare the field as
public?
Properties are not only used to provide access to fields of the class, but also used to
provide controlled access. Properties provide security to data and ensure that no
invalid values are assigned to the fields of the class.
class Student
{
public static void Main()
{
int[] rollNo = { 11, 12, 13 };
string[] studentName = { "David", "Sam", "John" };
Array.Resize<int>(ref rollNo, 5);
Array.Resize<string>(ref studentName, 5);
rollNo[3] = 14;
rollNo[4] = 15;
studentName[3] = "Sandra";
studentName[4] = "Michelle";
System.Console.WriteLine("Roll No. \tStudent Name");
for (int i = 0; i < rollNo.Length; i++)
{
System.Console.WriteLine("{0}
\t\t{1}",rollNo[i],
studentName[i]);
}
}
}
class Company
{
public static void Main()
{
ArrayList objCustomers = new ArrayList();
ArrayList objSuppliers = new ArrayList();
objCustomers.Add("Olive Brown");
objCustomers.Add("Elvis Davis");
objCustomers.Add("Nicole Anderson");
objSuppliers.Add("Garry White");
objSuppliers.Add("Nancy Scott");
objSuppliers.Add("Carter Jason");
objSuppliers.Add("Smith Kidman");
objCustomers.AddRange(objSuppliers);
Console.WriteLine("List of customers : ");
foreach (object name in objCustomers)
{
System.Console.WriteLine(name);
}
}
}
It is also possible to copy the results, after AddRange() method is called into a
new array.
Can the get and set accessors of a property have different access
modifiers?
No, you cannot have different access modifiers on the get and set accessors of a
property. When a property is declared with a particular access modifier, it applies to
both the get and set accessors of the property. However, if you want them to be
different, you can create a read-only property by using the get accessor and then,
create a private or an internal set accessor that is not associated with the
property.
Why are data members of the Hashtable class stored using the
private access modifier?
Data members of the Hashtable class are stored using the private access
modifier to ensure data integrity. This allows only the member functions to access
the data members of the Hashtable class.
What is an assembly?
An assembly is a file that contains the intermediate language code. When a
particular program is successfully compiled, the C# compiler automatically
generates an assembly file, which can be either a dll (dynamic link library) file or an
executable file. An assembly is generated only once for the program and is
appropriately updated every time the program is compiled.
Are all the features of C# 7.1 made available by default to the users?
While C# 7.1 is supported by the .NET Core SDK 2.0 or Visual Studio 2017, its
features are unavailable until the user changes the language version setting for the
opened project. In other words, the user is required to modify the project’s
configuration settings for specifying the intended language version.
.NET Core can be used when the Command Line Interface (CLI) control is required.
A few users would rather prefer to work in lightweight editors and command line
control. .NET Core offers a CLI for all supported platforms and it involves minimal
installation on production machines.
.NET Core can be utilized when Docker containers are being employed. Generally,
containers and microservices architecture are used in conjunction. Due to its
lightweight and modular features, .NET Core operates well with containers. It allows
server apps to set up cross-platform to Docker containers. Though, .NET Framework
can be utilized for containers, the image size will be larger.
What is a docker?
Docker is a computer program that carries out operating-system-level virtualization,
which is referred to as containerization.