Category >
CSHARP
|| Published on :
Wednesday, November 11, 2020 || Views:
941
||
C# interview Question And Answer 2020 - part 2
1. How do I declare inout arguments in C#?
The equivalent of inout in C# is ref. , as shown in the following
example:
public void My1 (ref String str1, out String str2)
{
...
}
When calling the method, it would be called like this: String s1;
String s2;
s1 = "Hi";
My1(ref s1, out s2);
Console.WriteLine(s1);
Console.WriteLine(s2);
Notice that you need to specify ref when declaring the function and calling it
2. Can you change the value of a variable while debugging a C# application?
Yes, you can change the value of a variable while debugging a C# application.
3. What is the difference between const and static read-only?
static read only can be modified by class that containing whereas const can never be modified.
4. What namespaces are necessary to create a localized application?
System.Globalization, System.Resources
5. How do you inherit from a class in C#?
Place a colon and then the name of the base class.
6. Does C# support parametrized properties?
C# does not support parametrized properties. However it supports the concept of indexer. An indexer is a member which enables the object to be indexed as in array.
7. Does C# support C type macros?
C# doesn't support C type macros. Some of the C macros are found in .NET class but they only work with debug builds.
8. How do I convert a string to an int in C#?
Convert.ToInt32 is the keyword to be used to convert string to int.
For eg:-
class ConvStrtoInt
{
public static void Main()
{
String str = "2345";
int x = Convert.ToInt32(str);
Console.WriteLine(x);
}
}
9. What is the .NET datatype that allows the retrieval of data by a unique key?
HashTable is the datatype to be used to retrieve data by unique key.
10. What is the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
11. How can I get the ASCII code for a character in C#?
Casting the char to an int will give you the ASCII value: char c = 'f'; System.Console.WriteLine((int)c); or for a character in a string: System.Console.WriteLine((int)s[3]); Even the base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.
12. How do I create a Delegate/MulticastDelegate?
C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name.
For example,
System.Threading.ThreadStart: Foo MyFoo = new Foo();
ThreadStart del = new ThreadStart(MyFoo.Baz);
13. How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.
14. What are the ways to deploy an assembly?
Some of the ways to deploy assembly are as follows:-
MSI installer
XCOPY
CAB archive
15. Difference between imperative and interrogative code.
There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.
16. Difference between imperative and interrogative code.
There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.
17. Explain manifest & metadata?
Manifest is metadata about assemblies. Metadata is machine-readable information about a resource, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.
18. Difference between value and reference type. what are value types and reference types?
Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap
19. What are the two kinds of properties.
Two types of properties in .Net: Get and Set
20. What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.