Depth. NET platform and C # programming internal test Pen questions

Source: Internet
Author: User

1: In C #, the classes related to file operations are correct (AB) < select two Items >

The A:fileinfo class provides an instance method for manipulating files

The B:file class provides a static method for manipulating files

The C:directory class provides an instance method of manipulating the directory

The D:directoryinfo class provides a static method for manipulating the directory

Analytical:

The DirectoryInfo class provides an instance method of manipulating the directory

The directory class provides a static way to manipulate the directory

2: The following option (AD) can cause the following code to appear as an error. < select two Items >

Student s=new Student ();

S.name= "Marry";

A: Set the Name property in the student class to read-only property

B: Set the Name property in the student class to write-only property

C: Add parameterless constructors to the student class

D: Adding a parameterized constructor to the student class

3: When creating a file stream in. NET, you need to specify the value of the file mode FileMode, and the following values for FileMode are interpreted correctly (AC)

< select two Items >

A:create: Creates a new file with the specified name. If the file exists, overwrite the original

B:createnew: Create a new file. If it already exists, no processing is done

C:open: Opens a file. File must exist, otherwise error

D:openorcreate: Opens or creates a new file. If the file does not exist, create a new but not open it

Analytical:

B:createnew Create a new file. If an exception occurs when the file exists, the hint file already exists.

D:openorcreate: If the file does not exist, create a new file with the specified name and open it

4: In. NET in the use of files, you will often encounter garbled problem, the following options in the garbled statement is correct (C)

A: Handling garbled use encoding,encoding is an enumeration type

B: When writing the contents of the file to specify its encoding format, you can avoid garbled

C: When reading the file, specify the parsing file encoding format, can solve the garbled problem

D:encoding in the System.Data namespace

Analytical:

The use of files garbled nature is the file saved encoding and read the encoding method used inconsistent. Writing to the file specifies the encoding format, does not solve the problem, when reading the file, the specified and the text is saved in a consistent encoding format, no garbled; encoding in the System.Text namespace

5: In. NET, the following about the directory class and the DirectoryInfo class is correct (a)

The methods of the A:directory class are static and can be called directly

The methods of the B:directoryinfo class are static and can be called directly

Both the C:directory class and the DirectoryInfo class can use the exist () method to verify that the specified directory exists

The GetFile () method of the D:directory class returns an array of FileInfo objects under the specified directory

Analytical:

The methods of the directory class are static and can be called directly, and the method of the DirectoryInfo class is not static, so it is called by instantiation. Directory contains the exist () method, DirectoryInfo contains the exist property, and the GetFiles () method of the Directory class returns an array of file name strings in the specified directory

6: In the following C # code, the line fill (BD) does not go wrong. < select two Items >

Dictionary<int,string>dic=new dictionary<int,string> ();

Dic. ADD (1, "C#oop");

Console.WriteLine (_____________);

a:dic["C#oop"]

B:dic[dic. Count]

C:DIC[0]

D:DIC[1]

7: In C # code, the result of the following code output is (C)

Class Program

{

int num=10;

static void Main (String[]args)

{

Console.WriteLine (num++);

}

A:11

B:10

C: Compile Error

D: Run an error

Analytical:

Static members can only be called through the class name, only static members can be called in static methods, and non-static members must be called through the object. So program compilation does not pass

8: In C #, the statement about generic collections and ArrayList is correct (C) < Select an item >

A: When adding elements to ArrayList, you can add only one type of element < can add multiple types of elements >

B: Do not need to do type conversion when reading elements from ArrayList < need to type conversion >

C: Use generic collections to reference System.Collections.Generic namespaces

D:arraylist Add, read without boxing, unpacking < If the element added to ArrayList is a value type, the elements will be boxed into an object reference type and then saved >

9: In C #, use the collection initializer to initialize the collection using the correct (BC) < select two Items >

The A://se class is a class that has already been defined

List<se>list=new list<se> (New SE (), New SE ());

The B://se class is a class that has already been defined

List<se>list=new list<se>{new SE (), New SE ()};

C:arraylist list=new arraylist{1,2};

D:arraylist list=new ArrayList () {1;2};

Analytical:

Initialize multiple elements with {} instead of (), so a error, multiple elements are separated by commas instead of semicolons, so D is wrong, as for the collection type can be parentheses or without parentheses, so BC can

10: In C #, the following code executes the result (B).

public struct Test

{

public int num;

}

public class Test1

{

public static void Change (test t1,ref test T2)

{

t1.num++;

t2.num++;

}

public static void Main ()

{

Test T1;

T1.num=1;

Test T2;

t2.num=2;

Change (T1,ref T2);

Console.Write (t1.num+ "," +t2.num);

}

}

a:1,1

b:1,3

c:2,2

d:2,1

Analytical:

A ref-decorated value type is passed by reference type, the struct is a value type, the T1 is not modified with ref, the value does not change, T2 uses the ref modifier, and the value changes

11: In C #, the Apple class is defined as a subclass of the fruits class, and the following statements cannot be used to convert the fruits type to Apple type (AD) < select two Items >

A:fruits fru=new Apple ();

Apple App=fru is Apple;

B:fruits fru=new Apple ();

Apple App=fru as Apple;

C:fruits fru=new Apple ();

Apple app= (apple) Fru;

D:fruits fru=new Apple ();

Fru. Convert (Apple);

Analytical:

A is used to determine that D does not have the syntax of convert

12: The following C # code will appear error when running (BC) < select two Items >

A:arraylist a1=new ArrayList ();

A1. ADD (100);

A1. ADD (100);

B:hashtable ht=new Hashtable ();

Ht. Add ("Zhang San", new Object ());

Ht. Add ("Zhang San", new Object ());

C:list<string>list=new list<string> ();

String name=list[0];

D:dictionary<string,object>dict=new dictionary<string,object> ();

foreach (Onject p in Dict. Values) {}

Analytical:

B, the Hashtable key cannot appear duplicates.

C, no subscript 0

13: In C #, the following code runs as a result (a)

public class Fruit

{

public virtual void Show ()

{

Console.WriteLine ("Different flavors of fruit");

}

}

public class Lemon:fruit

{

public override void Show ()

{

Console.WriteLine ("Lemon is sour!") ");

}

}

Class Program

{

static void Main (String[]args)

{

Fruit Lemon =new Fruit (); <new is the parent class object, so the method of the parent class is output >

Lemon. Show ();

}

}

A: Output "fruit tastes different"

B: Output "lemon is sour!"

C: The program is not error, but nothing is output

D: Program error, prompt object type inconsistent

14: Run the following C # code, then the output is (D)

public class Child

{

public virtual void like ()

{

Console.WriteLine ("Children like Toys");

}

}

public class Boy:child

{

public override void-like (string toys)

{

Console.WriteLine ("Boys Like" +toys);

}

}

Class Program

{

static void Main (String[]args)

{

Child child=new Child ();

Child. Like ("Toy Pistol");

}

}

A: Kids like toys

B: Boys Like toy pistols

C: Kids like toys

Boys Like toy Pistols

D: Program compile error, nothing output

Analytical:

Boy.like (String) did not find a suitable method to override

Depth. NET platform and C # programming internal test Pen questions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.