.NET Quiz (Q1-Q4)
A quick way to measure your understanding of .NET is to take some quiz questions. And from time to time, I will offer some for your enjoyment. The answers will be given out either in the comment and/or in the next Quiz blog. Of course, you can usually get the answers by testing the code yourself or checking out MSDN.
Q1: CAS (Code Access Security) is a/an ____ -based security system.
(1) Access (2) Code (3) Evidence (4) Permission (5) Principal
Q2: Class SuperList implements an indexer: public string this [int index]; When index is not within valid range, the indexer should throw:
(1) NotSupportedException (2) IndexOutOfRangeException
(3) InvalidOperationException (4)ArgumentOutOfRangeException
Q3: Which one complies with .NET design naming guideline:
(1)CLSCompliantAttribute (2)HttpSessionState.SessionID
(3)Color.FromArgb (4)System.MarshalByRefObject
Q4: Which one works without an exception:
(1) object[] demo = new object[10];
demo[10] = "demo10";
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
(2) System.Collections.ArrayList demo = new System.Collections.ArrayList(10);
demo[9] = "demo9";
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
(3) System.Collections.Hashtable demo = new System.Collections.Hashtable(10);
demo[8] = "demo8";
(This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm)
# re: .NET Quiz (Q1-Q4)
A2: (4)
A3: (4)
A4: (2)
Not all that sure about Q1, but the rest I'm pretty confident :)
# re: .NET Quiz (Q1-Q4)
Should I congratulate you? :-)
# re: .NET Quiz (Q1-Q4)
A2: (4)
A3: (1)
A4: (1)
What about these?
# re: .NET Quiz (Q1-Q4)
# re: .NET Quiz (Q1-Q4)
A2: (4)
A3: (2)
A4: (3 i guess)
for q4 i really want to answer 2, but you've already said that that's wrong. :)
# re: .NET Quiz (Q1-Q4)
System.Collections.ArrayList demo = new System.Collections.ArrayList(10);
demo[9] = "demo9";
will result in ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Geoff, you get 3 question (1, 2, and 4) correct.
# re: .NET Quiz (Q1-Q4)
# re: .NET Quiz (Q1-Q4)
# re: .NET Quiz (Q1-Q4)
After the constructor:
demo.Capacity is 10 but demo.Count is 0.
So even demo[0] will throw ArgumentOutOfRangeException.
You can add items into demo using Add(object); method. indexer can be used to retrieve and update item values but not to add new items.
# re: .NET Quiz (Q1-Q4)
A1: (2, 3 and 4)
A2: (2)
A3: (3 and 4)
A4: (3)
About Q2: What is the reason tho throw an ArgumentOutOfRangeException instead of an IndexOutOfRangeException? After all, it is an index that is incorrect, isn't it?
About Q3: I see the problems with the first two answers, but what is the correct answer, and why is the other one of 3/4 wrong?
# re: .NET Quiz (Q1-Q4)
# re: .NET Quiz (Q1-Q4)
For Q3: Correct answer is (3).
MarshalByRefObject should have been MarshalByReferenceObject
In summary, correct answers for Q1 through Q4 are: 3, 4, 3, 3