C#.Net written test questions final test questions with answers

  1. The () method of the File class in C# can check whether the specified file exists. A
    A:Exists( )
    B:Copy( )
    C:Move( )
    D:Delete( )

  2. In .NET, the following description about .NET Framework is wrong ( ). D
    A: The .NET framework can be installed on the Windows operating system
    B: The .NET framework runs on the operating system
    C: The .NET framework supports C#, VB.NET, C++ and other development languages
    ​​D: The .NET application cannot run on linux

  3. In C#, the following description of static methods and instance methods is wrong ( ). C
    A: Static methods need to be modified with the static keyword
    B: Static methods cannot directly access instance members
    C: Instance methods cannot directly access static members
    D: Instance methods must be called using instance objects

  4. In C#, if you want to realize that the members of the parent class can be accessed in the parent class and its subclasses, but cannot be accessed in other classes, you should use the () modifier to modify the member. D
    A: public
    B: private
    C: base
    D: protected

  5. Regarding inheritance in C#, the following statement is wrong ( ). A
    A: The protected members of the parent class cannot be accessed in the subclass
    B: Through class inheritance, the functions of the class can be extended and the functions of the class can be reused
    C: public class Student : Person indicates that the parent class of Student may be Person
    D: Inheritance must conform to the relationship of is-a

  6. In C#, the following statement about inheritance is wrong ( ). C
    A: The subclass can derive subclasses
    B: The subclass is the derived class of the parent class
    C: The subclass can inherit and access the private members of the parent class
    D: A subclass cannot inherit multiple parent classes

  7. In C#, the following ( ) collections are organized by key and value. BD
    A:ArrayList
    B:Hashtable
    C:List
    D:Dictionary<K,V>

  8. In C#, the correct way to write the constructor of the following Teacher class is ( ). AC
    A:

public Teacher (){
    
      }

B:

private void Teacher (){
    
      }

C:

private Teacher (int id,string name) {
    
      }

D:

public int Teacher (int id,string name) {
    
      }
  1. In C#, the following statements about boxing and unboxing are correct ( ). A
    A: The process of converting a value type to a reference type is called boxing, and vice versa, it becomes unboxing
    B: The process of converting a value type into a reference type is called unboxing, and vice versa, it becomes boxing
    C: Use boxing and unpacking Box, which can improve program performance
    D: After the value type data is boxed, it cannot be modified

  2. Run the following C# code, then output ( ). C

class Student
{
    
    
    public static int id = 1;
    public static void Alter()
    {
    
    
        id++; 
    }
}
class Program
{
    
    
    static void Main(string[] args)
    {
    
    
        Student stu = new Student();
        Student.id++;
        Student.Alter();
        Console.WriteLine(Student.id);
    }
}

A:1
B:2
C:3
D: The program runs wrong and does not output any results

  1. In C#, the Student class inherits from the Person class, where stuObj is the Student object, perObj is the Person object, and the type conversion in the following code is ( ). AD
    A:perObj as Student
    B:perObj is Student
    C:stuObj is Person
    D:(Student) perObj

  2. Regarding the base keyword of C#, the statement is wrong ( ). A
    A: Members decorated with the base keyword in the parent class, subclasses can use base to access
    B: base keyword can call the properties of the parent class
    C: base keyword can call the method of the parent class
    D: base keyword You can call the constructor of the parent class

  3. Run the following C# code, the program will output ( ). B

int num1 = 10;
Object obj = num1;
num1++;
Console.WriteLine("obj={0},num1={1}", (int)obj, num1);

A:obj=11,num1=10
B:obj=10,num1=11
C:obj=10,num1=10
D:obj=11,num1=11

  1. In the following C# code, Book is a book class, and its Name property can be initialized through the Book class constructor, then the output result of the following code is ( ). A
    Dictionary<string, Book> books = new Dictionary<string, Book>();
    books.Add(“1001”, new Book(“C#OOP”));
    Console.WriteLine(books[“1001”].Name );
    A: C#OOP
    B: Book
    C: 1001
    D: Program error

  2. Run the following C# code, the following statement is correct ( ). B

public class Student
{
    
    
    public int age;
}
public class Program
{
    
    
	static void Alter(Student stu) 
	{
    
    
       stu.age++;
    }
	static void Main()
	{
    
    
       Student stu = new Student();
       stu.age = 30;
       Alter(stu);
       Console.WriteLine("age={0} ",stu.age);
    }
}

A: The program is running normally, output: age=30
B: The program is running normally, output: age=31
C: The program is wrong, output: age=31
D: The program is wrong, nothing is output

  1. In a console application, the output of the following C# code is ( ). B
static void Main(string[] args)
{
    
    
    int num1 = 10, num2 = 20;
    fun(num1, ref num2);
    Console.WriteLine("num1:" + num1 + ",num2:" + num2);
}
static void fun(int num1,ref int num2)
{
    
    
    num1 += num2;
    num2 += num1;
    Console.WriteLine("num1:"+num1+",num2:"+num2);
}

A:

num1:30,num2:50
num1:30,num2:50

B:

num1:30,num2:50
num1:10,num2:50

C:

num1:30,num2:50
num1:10,num2:20

D:

num1:10,num2:20
num1:10,num2:20
  1. In C#, the running result of the following code is ( ). A
public class Fruit
{
    
    
	public virtual void Show()
	{
    
    
		Console.WriteLine("水果的味道不同!"); 
	}
}
public class Lemon: Fruit 
{
    
    
	public override void Show(){
    
    
		Console.WriteLine("柠檬是酸的!"); 
    }
}
class Program
{
    
    
	static void Main(string[] args)
	{
    
    
		Fruit lemon = new Fruit ();
		lemon. Show();
    }
}

A: Output "The taste of fruit is different!"
B: Output "Lemon is sour!"
C: The program does not make an error, but nothing is output
D: The program makes an error, prompting that the object types are inconsistent

  1. Regarding the following C# code, the correct statement is ( ). D.
public struct Student
{
    
    
	public int id;
    public int age;
    public void Say()
    {
    
    
		Console.WriteLine("hello!");
    }
}
class Program
{
    
    
	static void Main(string[] args)
    {
    
    
		Student stu;
        stu.id = 1;
        stu.age = 20;
        stu.Say();       
	}
}

A: The method cannot be defined in the structure, so it is wrong to define the Say() method in the Student structure
B: Student stu; this code is wrong because the structure object must be instantiated with the new keyword
C: There is no error in the code, but the program runs No result will be output
D: The code is error-free, the program can be executed normally, and "hello!" will be output

  1. The result of running the following C# code is ( ). D.
public abstract class FaClass
{
    
    
    public void FaClass()
    {
    
    
        Console.Write("1");
    }
    abstract public void ABSMethod();
}
public class SonClass : FaClass
{
    
             
    public SonClass()
    {
    
    
        Console.Write("2");
    }
    public override void ABSMethod()
    {
    
    
        Console.Write("3");
    }
    static void Main()
    {
    
    
        SonClass objB = new SonClass();
        objB.ABSMethod();
    }
}

A:12
B:21
C:13
D:23

  1. The output of the following C# code is ( ). B
public class Person
{
    
    
    public Person()
    {
    
     
		Console.WriteLine("无名英雄"); 
	}
    public Person(string name)
    {
    
     
		Console.WriteLine("我叫" + name);
	}
}
public class Student : Person
{
    
    
    public Student(string name)
    {
    
     
		Console.WriteLine("我是" + name + "同学"); 
	}
    static void Main(string[] args)
    {
    
     
		Student student = new Student("孙悟空");
		Console.ReadLine();
	}
}

A: I am Sun Wukong
B: Unknown hero
I am Sun Wukong
C: My name is Sun Wukong
I am Sun Wukong
D: Unknown hero
My name is Sun Wukong
I am Sun Wukong

  1. Which of the following statements about abstract methods in C# is correct ( ). B
    A: Use virtual to modify
    B: Abstract methods have no method body
    C: Abstract methods must have abstract methods in abstract classes
    D: Abstract methods in non-abstract classes can have method bodies

  2. In the .NET framework, the common language runtime (CLR) consists of () two components. BD
    A:MSIL
    B:CLS
    C:FCL
    D:CTS

  3. In C#, the following ( ) is not a method of the File class. C
    A: Move() method
    B: Exists() method
    C: Update() method
    D: Delete() method

  4. Execute the following C# code, and the output result is ( ). D.

List<string> list = new List<string>();
list.Add("张三");
list.Add("李四");
list.Remove("张三"); 
Console.WriteLine(list[0]);

A: null
B: 0
C: Zhang San
D: Li Si

  1. In a C# program, you can use ( ) to get the value of the current node in the XML file. D
    A: Text property of XmlNode
    B: ChildNodes property of XmlNode
    C: Name property of XmlNode
    D: InnerText property of XmlNode

  2. In the following C# code, the number of times to perform boxing is ( ). B

static void Main(string[] args)
{
    
    
     int i = 321;
     object o = i;
     float j = (float)o;
     Console.WriteLine(j);
}

A:0
B:1
C:2
D:3

  1. In C#, the following code operates on the control tvMenu (TreeView control), and the following option description is wrong ( ). C
this.tvMenu.Nodes.Add("节点"); //代码1
this.tvMenu.SelectedNode.Remove();//代码2
this.tvMenu. SelectedNode.Nodes.Clear();//代码3
this.tvMenu.Nodes.Clear();//代码4

A: Execute "Code 1" to add a node to tvMenu
B: Execute "Code 2" to delete the currently selected node in tvMenu
C: Execute "Code 3" to clear the currently selected node and its child nodes in tvMenu
D: Execute "Code 4" to clear the tvMenu all child nodes

  1. In the .NET framework class library, the following () namespaces are used to access ADO.NET. B
    A: System
    B: System.Data
    C: System.Net
    D: System.Collections.Generic

  2. Regarding the following C# code, the statement is incorrect ( ). C

Dictionary<string, Student> student = new Dictionary<string, Student>();
student.Add("s001",new Student("Mike"));
student.Add("s002",new Student("张三"));
student.Remove(0);
Console.WriteLine(student.Values.Count);

A: The collection student stores data in the form of key-value pairs
B: Two student objects are stored in the collection student, the keys are "s001" and "s002" respectively
C: The program has no errors, and the output is 2
D:student.Remove( 0); This line of code has an error

  1. For the following C# code, if the ToLive() method of the Person class needs to be rewritten in the Hero class, the horizontal lines should be filled in ( ) in sequence. D.
public class Person
{
    
    
    public ________ void ToLive()
    {
    
     Console.WriteLine("生下来,活下去");}
}
public class Hero : Person
{
    
    
    public ________ void ToLive()
    {
    
    Console.WriteLine("生当作人杰,死亦为鬼雄");}
}

A:不填 不填
B:override virtual
C:不填 override
D:virtual override

  1. Read the following C# code, the correct statement in the option is (). D.
  public class A
    {
    
    
        public int sign1;
    }
    public class B
    {
    
    
        public int sign2;
    }
    public class C : A,B
    {
    
    
        public int sign3;
        static void Main(string[] args)
        {
    
    
            C objC = new C();
            objC.sign1 = 1;
            objC.sign2 = 2;
            objC.sign3 = 3;
            Console.WriteLine(objC.sign1+","+objC.sign2+","+objC.sign3);
        }
    }

A: Running the program will output: 1, 2, 3
B: Class C is a subclass of Class A and Class B, so Class C inherits all members of Class A and Class B
C: Class C can only inherit from Class A Member, cannot inherit member D of class B
: program compilation error, prompting that C cannot have multiple base classes A and B

  1. In the following C# code, the subclass constructor in the option calls the parent class constructor is correct ( ). D.
public class Person
{
    
    
    public string name;
    public Person(string name)
    {
    
     this.name = name; }
}
public class Hero : Person
{
    
     //需要显式调用父类Person(string name)构造函数 }

A:

public Hero(string name)
{
    
     Person(name); }

B:

public Hero(string name)
{
    
     base (name); }

C:

public Hero(string name): Person(name){
    
     }

D:`

public Hero(string name): base(name){
    
     }`
  1. In C#, the correct statement about classes related to file operations is ( ). AB
    A: FileInfo class provides instance methods for operating files
    B: File class provides static methods for operating files
    C: Directory class provides instance methods for operating directories
    D: DirectoryInfo class provides static methods for operating directories

  2. In C#, the method ( ) of the following File class can move the specified file to a new path. D
    A:

Delete(string filename1,string filename2)

B:

Copy(string filename1,string filename2)

C:

Exists(string filename1,string filename2)

D:

Move(string filename1,string filename2)
  1. In C#, use the following () keywords to define structures. B
    A: static
    B: struct
    C: abstract
    D: enum

  2. The ones that can form method overloading with the following C# methods are ( ). cd

public int Fun(int p)
{
    
    }

A:

public int Fun(int p2)
{
    
    }

B: pu

blic int Fun2(int p)
{
    
    }

C:

public string Fun(string p)
{
    
    }

D:

public bool Fun(bool p)
{
    
    }
  1. Which of the following statements about parsing XML is correct ( ). B
    A:XML is called Extensible Markup Language, its syntax is completely consistent with HTML
    B:XmlNode represents a node in XML
    C:XmlDocument object can represent the entire XML document, use the Save() method to read the specified XML file into the XmlDocument object
    The property ChildNode of the D:XmlNode object represents all child nodes of the current node

  2. In C#, the following statement about the generic collection Dictionary<K,V> is wrong ( ). B
    A:Dictionary<K,V> accesses elements without type conversion
    B: Adding/reading value type elements requires unboxing and boxing
    C: Value can be obtained through Key
    D:Dictionary<K,V> is through key/value pairs save element's

  3. In C#, the following statement about the base keyword is correct ( ). BD
    A: The base keyword is used exactly the same as the this keyword
    B: In a subclass, you can use the base keyword to access the public properties of the parent class. The syntax is: base. Attribute of the parent class
    C: In the subclass, you can use the base keyword to call the constructor of the parent class to realize the initialization of the inherited attribute. The syntax is: base. parent class constructor ( )
    D: In a subclass, the base keyword cannot access the private field of the parent class

  4. In C#, the following statements about structures are wrong ( ). AB
    A: The structure is a reference type
    B: Like a class, the new keyword must be used when defining the object of the structure
    C: The struct keyword is used to define the structure
    D: There can be fields or methods in the structure

  5. The core components of the .NET framework include ( ). BD
    A:CTS
    B:CLR
    C:CLS
    D:FCL

  6. In C#, the following statement about XML is incorrect ( ). A
    A: XML is called Extensible Markup Language, its syntax is completely consistent with HTML
    B: XmlNode represents a node in XML
    C: XmlDocument object can represent the entire XML document, use the Load() method to read the specified XML file into the XmlDocument object
    The property ChildNodes of the D:XmlNode object represents all child nodes of the current node

  7. Run the following C# code, the line of code that may go wrong is ( ). C

class Student
{
    
    
    public static int id =1;  //1
    int age=20;
    public static void Alter()
    {
    
    
        id++;   //2
        age++;  //3
    }
}
class Program
{
    
    
    static void Main(string[] args)
    {
    
    
        Student stu = new Student();     
        stu.Alter();  //4       
    }
}

A:1
B:1、2
C:3、4
D:1、2、3、4

  1. In C#, regarding inheritance and method rewriting, the following statement is correct ( ). D
    A: The virtual method of the parent class cannot be rewritten by the subclass of the subclass
    B: After the method of the parent class is rewritten by the subclass, it cannot be called by the parent class object
    C: Only the method modified with the virtual keyword can be rewritten
    D: Use the override keyword to implement method rewriting

  2. In C#, the correct statement about boxing and unboxing is ( ). AD
    A: The process of converting a value type to a reference type is called boxing, and vice versa, called unboxing
    B: Unboxing is performed implicitly and does not require explicit conversion
    C: In actual development, boxing and unboxing operations It will improve the performance of the program
    D: There is no need to unbox and box when reading generic collection elements

  3. Execute the following C# code, the output result is ( ). B

public class Number
{
    
    
     public int num;
}
public class Program
{
    
    
     static void Change(Number n) 
     {
    
    
          n. num = 17;
     }
     static void Main()
     {
    
    
          Number n = new Number();
          n. num = 7;
          Change(n);
          Console.WriteLine(n. num);
     }
}

A:7
B:17
C:717
D: Program compilation error

  1. In C#, the running result of the following code is ( ). B
class Temp
{
    
    
	int _iCnt;
    public Temp(int iName)
	{
    
    
        _iCnt = iName;
    }
    public Temp()
	{
    
    
        _iCnt = 9;
    }
    public void Sum(int iName)
	{
    
    
        _iCnt += iName;
    }
    public void Output()
	{
    
    
        Console.WriteLine(_iCnt);
        Console.ReadLine();
    }
}
class Program
{
    
    
    static void Main(string[] args)
	{
    
    
		Temp temp = new Temp(5);
		temp = new Temp();
		temp.Sum(4);
		temp.Output();
    }
}

A: 18
B: 13
C: 9
D: compilation error

  1. In .NET, the following description about boxing and unboxing is correct (A).
    A: int i=32;
    object o = (object) i;
    this is a boxing operation
    B: double num1=11.49;
    int num2 = (int) num1;
    this is an unboxing operation
    C: unboxing is to convert the value type into Reference type
    D: Boxing and unboxing operations have no effect on program performance
  2. In C#, what is wrong about the following code is (B).
try
{
    
    
}
catch (SqlException ex)
{
    
    
  throw ex;    
}
catch (IOException ex)
{
    
    
   return null;  
}
finally
{
    
     
}

A: The order of the two catch blocks can be reversed, which will not affect the handling of exceptions
B: The above code can catch any exception in the try block
C: If an IO exception occurs, the above code cannot normally report an error
D: The finally block will eventually execute
50 . In the .NET platform, the following (C) is not part of the .NET assembly.
A: Assembly list
B: Type metadata
C: Data configuration file
D: MSIL code
51. In C#, regarding method rewriting, the following statement is correct (BD).
A: Method rewriting is method overloading. The two are the same thing, but they are just two names.
B: Method rewriting is the subclass rewriting the method of the parent class.
C: The method modified with the virtual keyword cannot be used Rewrite
D: Use the override keyword to implement method rewriting
52. In C#, there is the following SetData method, and the following options (AC) are not overloaded methods of the SetData method.

public int SetData (int iCnt,double dBnt){
    
    ……//省略具体处理方法}

A:

public double SetData (int iCnt,double iBnt){
    
    ……}

B:

public int SetData (int iCnt, double dBnt,int iZnt){
    
    ……}  

C:

private int SetData (int iCnt,double dBnt){
    
    ……}

D:

public int SetData (double dBnt, int iCnt){
    
    ……}

Guess you like

Origin blog.csdn.net/u011731544/article/details/129982227
Recommended