.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)

Published Monday, June 28, 2004 6:40 PM by zhanbos
Filed under: Quiz

Comments

Monday, June 28, 2004 7:17 PM by Chad Myers

# re: .NET Quiz (Q1-Q4)

A1: (3)
A2: (4)
A3: (4)
A4: (2)

Not all that sure about Q1, but the rest I'm pretty confident :)
Monday, June 28, 2004 7:23 PM by Zhanbo Sun

# re: .NET Quiz (Q1-Q4)

Chad, you get the first 2 questions correct.
Should I congratulate you? :-)
Monday, June 28, 2004 7:30 PM by Allen Lee

# re: .NET Quiz (Q1-Q4)

A1: (3)
A2: (4)
A3: (1)
A4: (1)

What about these?
Monday, June 28, 2004 7:58 PM by Zhanbo Sun

# re: .NET Quiz (Q1-Q4)

Allen, you get the first 2 questions correct.
Monday, June 28, 2004 9:56 PM by Geoff Appleby

# re: .NET Quiz (Q1-Q4)

A1: (3)
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. :)
Monday, June 28, 2004 10:01 PM by Zhanbo Sun

# re: .NET Quiz (Q1-Q4)

For Q4, Answer 2:
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.

Monday, June 28, 2004 10:09 PM by Geoff Appleby

# re: .NET Quiz (Q1-Q4)

Isn't [9] within the range of a 10 item arraylist? starting 0 based, then item 9 is the 10th item...
Monday, June 28, 2004 10:10 PM by Geoff Appleby

# re: .NET Quiz (Q1-Q4)

Oh, and as for getting Q3 wrong, i can't say i'm surprised. I hate the 'correct' naming conventions - give me Camel Case any day :)
Monday, June 28, 2004 10:23 PM by Zhanbo Sun

# re: .NET Quiz (Q1-Q4)

For ArrayList Constructor (Int32); constructor, note what MSDN says: Initializes a new instance of the ArrayList class that is 'empty' and has the specified 'initial capacity'.

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.
Monday, June 28, 2004 11:39 PM by Luc Cluitmans

# re: .NET Quiz (Q1-Q4)

Hmm, trying not to look at previous answers, I would have guessed:
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?

Tuesday, June 29, 2004 12:49 AM by Adrian Florea

# re: .NET Quiz (Q1-Q4)

A "Quiz Sharp" series (till now 28 episodes) you can find at my blog (http://www.ugidotnet.org/7322.blog)
Tuesday, June 29, 2004 12:01 PM by Zhanbo Sun

# re: .NET Quiz (Q1-Q4)

For Q2: IndexOutOfRangeException is thrown when an attempt is made to access an element of an 'array' with an index that is outside the bounds of the array.

For Q3: Correct answer is (3).
MarshalByRefObject should have been MarshalByReferenceObject

In summary, correct answers for Q1 through Q4 are: 3, 4, 3, 3
posted @ 2007-12-04 17:36  许晓光  阅读(410)  评论(0编辑  收藏  举报