C# Interview Questions and Answers (958) - Page 22

How does C# differ from C++?

C# differs from C++ as follows:

1) C# does not support #include statement. It uses only using statement.
2) In C# , class definition does not use a semicolon at the end.
3) C# does not support multiple code inheritance.
4) Casting in C# is much safer than in c++.
5) In C# switch can be used on string values.
6) As compared to C++, Command line parameters array behave differently in C#.
What is Jagged Array?

An array whose elements are arrays is known as a jagged array.The elements of this jagged array can be of different dimensions and sizes.
A jagged array is sometimes called as an array–of–arrays.
What is the difference between ref & out parameters?

An argument passed to a ref parameter must first be initialized.
When compared this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.
Can “this” be used within a static method?

No ‘This’ cannot be used in a static method. This is because, only static variables/methods can be used in a static method.
What are the two data types available in C#?

The two data types available in C# are:

1) Value Type
2) Reference Type.

Value types are stored in the Stack.
Examples : bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort.

Reference types are stored in the Heap.
Examples : class, delegate, interface, object, string.
What is the difference between console and window application?

A console application is designed to run at the command line with no user interface.
A Windows application,which has a user interface, is designed to run on a user’s desktop.
How do I declare a pure virtual function in C# ?

By using the abstract modifier on the method and also the class must be marked as abstract. Note that abstract methods cannot have an implementation (unlike pure virtual C++ methods).
Are all methods virtual in C# ?

No. Like C++, methods are non-virtual by default, but those methods can be marked as virtual methods.
Can I use exceptions in C# ?

Yes, you can use exceptions in C#. In fact exceptions are the recommended error-handling mechanism in C# (and in .NET in general). Most of the .NET framework classes use exceptions to signal errors.
Where we can use DLL made in C#.Net ?

In supporting .Net, we can use DLL made in C#.NET. This is because DLL made in C#.Net is semi compiled version and it is not a com object. It is used only in .Net Framework as it is to be compiled at runtime to byte code.
Is it possible to debug the classes written in other .Net languages in a C# project ?

It is definitely possible. As everyone knows .net can combine code written in several .net languages into one single assembly. This is also true with debugging.
Does C# has its own class library ?

C# does not have its own class library. The .NET Framework has a comprehensive class library, which C# can make use of it.
IS it possible to have different access modifiers on the get/set methods of a property ?

No. The access modifier on a property applies to both its get and set accessors. If you want them to be different, then make the property as read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.
Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace ?

No, there is no way to restrict to a namespace.The namespaces are never the units of protection. But if you’re using assemblies, you can use the ‘internal’ access modifier to restrict access to only within the assembly.
Is there an equivalent of exit() or quiting a C#.NET application ?

Yes, you can use System.Environment.Exit(int exitCode) to exit the application.
If it is a Windows Forms App, you can use Application.Exit().
IS goto statement supported in C# ? How about Java ?

Gotos are supported in C# to the fullest. In Java goto is a reserved keyword that provides absolutely no functionality.
What happens when you encounter a continue statement inside for loop ?

The control is transferred back to the beginning of the loop and the code for the rest of the loop is ignored.
Can you inherit from multiple base classes in C# ?

No. C# does not support multiple inheritance, so you cannot inherit from more than one base class. You can however, implement multiple interfaces.
Can we call a base class method without creating instance ?

Yes,It is possible,
1) If it is a static method.
2) By inheriting from that class.
3) From derived classes using base keyword.
In which cases you use override and new base ?

You can use the new modifier to explicitly hide a member inherited from a base class.
To hide an inherited member, you have to declare it in the derived class using the same name, and modify it with the new modifier.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories