Csharp.Net - ASP.NET (MCQ) questions and answers
Here, you can read Csharp.Net multiple choice questions and answers with explanation.
1) When the garbage collector runs. - Published on 31 Aug 15
a. It runs automatically
b. EveryDay
c. Every alternate day
d. When IIS restart.
Answer
Explanation
|
ANSWER: It runs automatically
Explanation: We create the object, use it and generally forget to delete. Garbage collector is automatic memory management process that releases the memory used by the objects. Garbage collector runs automatically and it checks for objects in the managed heap that are no longer being used by the application and performs the necessary action to regain memory. It allows us to develop an application without having worry to free memory.
|
|
2) Why should you write the cleanup code in Finally block? - Published on 31 Aug 15
a. Compiler throws an error if you close the connection in try block.
b. Resource cannot be destroyed in catch block.
c. Finally blocks run whether or not exception occurs.
d. All of the above
Answer
Explanation
|
ANSWER: Finally blocks run whether or not exception occurs.
Explanation: The finally block always executes whether exception occurs or not. Finally block run when control leaves a try statement. You can write all cleanup code in finally block.
Example: class Program { staticint a = 10, b = 0, c; static void Main(string[] args) {
try { c = a / b; } finally { Console.WriteLine(c); }
} }
|
|
3) Which of the following are reference types? - Published on 31 Aug 15
a. String
b. Exception
c. Class
d. All of the above
Answer
Explanation
|
ANSWER: All of the above
Explanation: No explanation is available for this question!
|
|
4) Which of the following are value types? - Published on 31 Aug 15
a. String
b. System .Value
c. System.Drawing
d. System.Drawing.Point
Answer
Explanation
|
ANSWER: System.Drawing.Point
Explanation: There are two types are available in C#. Value Type and Reference Type. Value type are allocated on stack and reference types are allocated on managed heap. Predefined datatypes, structures, enums are value types. Class, Sting, Object etc are reference types. In the above example Point is struct so it is value type.
|
|
5) How many readers can simultaneously read data with ReaderWriterLock if there is no writer locks apply? - Published on 31 Aug 15
a. 9
b. 11
c. 13
d. No Limit
Answer
Explanation
|
ANSWER: No Limit
Explanation: There is no limit for number of users to access the data if ReaderWriterLock is applied. By using ReaderWriterLock you can synchronize access to a resource. It allows concurrent read access to multiple users. ReaderWriterLock class is available in System.Threading namespace.
|
|
6) For locking the data with synchronization which class will be used? - Published on 31 Aug 15
a. Lock
b. Moniter
c. SyncLock
d. Deadlock
Answer
Explanation
|
ANSWER: Moniter
Explanation: By using Moniter class a block of code can be access by one thread at a time. Moniter.Enter() method allows only one thread to access the resource.
Example: public void ShowNumbers() { Monitor.Enter(this); try { for (int i = 0; i < 5; i++) { Thread.Sleep(100); Console.Write(i + ","); } Console.WriteLine(); } finally { Monitor.Exit(this); } }
|
|
7) Which delegate is required to start a thread with one parameter? - Published on 31 Aug 15
a. ThreadStart
b. ParameterizedThreadStart
c. ThreadStartWithOneParameter
d. None of the above
Answer
Explanation
|
ANSWER: ParameterizedThreadStart
Explanation: ParameterizedThreadStart is a delegate that refers to a method that have single parameter.
Example: class Program { static void Main(string[] args) { ParameterizedThreadStartts = new ParameterizedThreadStart(Counting); Thread obj = new Thread(ts);
obj.Start("careerride");
} static void Counting(Object obj) { stringstr=(string)obj; Console.WriteLine("Welcome at "+str); for (int i = 1; i <= 10; i++) { Console.WriteLine("Count: {0}", i); Thread.Sleep(10); } } }
|
|
8) Thread class has the following property.
A. ManagedThreadID B. IsBackground C. IsBackgroundColor D. Abort - Published on 31 Aug 15
a. 1, 2
b. 1, 4
c. 4
d. 1 ,2, 4
Answer
Explanation
|
ANSWER: 1, 2
Explanation: ManagedThreadID and IsBackground are the properties of Thread class. ManagedThreadID is used to get Gets a unique identifier for the current managed thread. IsBackground property is used to gets or sets a value to check whether or not a thread is a background thread
|
|
9) An assembly must have an permission to connect with web server is? - Published on 31 Aug 15
a. socketPermission
b. DnsPermission
c. WebPermission
d. TCPPermission
Answer
Explanation
|
ANSWER: WebPermission
Explanation: No explanation is available for this question!
|
|
10) You want to configure the application to use the following authorization rules in web.config file.
• Anonymous users must not be allowed to access the application. • All employees except ABC must be allowed to access the application. - Published on 31 Aug 15
a. <authorization> <deny users=”ABC”> <allow users=”*”> <deny users=”?”> </authorization>
b. <authorization> <allow users=”*”> <deny users=”ABC”> <deny users=”?”> </authorization>
c. <authorization> <allow users=”ABC”> <allow users=”*”> </authorization>
d. <authorization> <deny users=”ABC”> <deny users=”?”> <allow users=”*”> </authorization>
Answer
Explanation
|
ANSWER: <authorization> <deny users=”ABC”> <deny users=”?”> <allow users=”*”> </authorization>
Explanation: First you deny user ABC. Then you deny anonymous users access by writing <deny users=”?”>. And last we allow to all other users access. This is proper order of the elements for the requirements of this scenario.
|
|