Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

c. Interview questions and answers


May 12, 2021 C#



Below is W3Cschool for everyone to organize some of the more classic C ,interview questions, we may as well try, do not look at the answer, you can answer a few questions correctly?


1. Briefly describe access to private, protected, public, and internal modifiers

For:

private: A private member that is accessible inside the class (only from its claim context).

Protected: Protects members that are accessible inside the class and from classes derived from the class.

Friend: Friend, the code in the assembly that declares the friend element can access the element, not from outside the assembly.

Protected Friend: Can be accessed within a derived class or within the same assembly.

Public: Public members, fully public, with no access restrictions.

internal: Accessible within the same namespace. ( Rarely used)


2. List ASP.NET the values between the two pages

For:

1. Use QueenString, e.g....? i d=1;response. R edirect()....

2. Use the Session variable

3. Use Server.Transfer

4. Use Apps

5. Use Cache

6 Use the Itm property of HttpContext

7. Use files

8. Use the database

9. Use cookies


3. The rules for a column are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34... F ind out what the 30th digit is and implement it with a recursive algorithm

For:

public class MainClass 
{
     

    public static void Main()
    {
        Console.WriteLine(Foo(30));
          
    }

    public static int Foo(int i)
    {

        if (i <= 0) return 0;
        else if(i > 0 && i <= 2) return 1;
        else return Foo(i - 1) + Foo(i - 2);

    }

}

What .C in 4-year-olds? I s an event a delegate?

For:

A delegate is a method that substitutes one method as an argument to another.

Yes, an event is a special kind of delegate. F or example, the parameters in the onclick event are one way.


5. The difference between overload overloading and override override rewriting in the implementation of polymorphism

For:

Overload overloading is the same name of the method, with different parameters or parameter types, and multiple overloads to suit different needs.

Override is an override that overrides functions in a base class to implement polymorphisms.


6. Please program to implement a bubbling sorting algorithm?

For:

int [] array = new int [*];

  int temp = 0 ;

  for (int i = 0; i < array.Length - 1; i++){

        for (int j = i + 1 ; j < array.Length ; j++){

              if (array[j] < array[i]){

                    temp = array[i] ;

                    array[i] = array[j] ;

                    array[j] = temp ;
                  
        			}    
    		}  
}

Or

 public static void bubble_sort(int[] x)

        {

            for (int i = 0; i < x.Length; i++)

            {

                for (int j = i; j < x.Length; j++)

                {

                    if (x[i] < x[j])    //从大到小排序

                    {

                        int temp;

                        temp = x[i];

                        x[i] = x[j];

                        x[j] = temp;

                    }

                }

            }

        }

        static void Main(string[] args)

        {

            int[] huage = { 1, 5, 2, 9, 3, 7, 6,4,8,0};

            bubble_sort(huage);

            foreach (var a in huage)

            {

                Console.WriteLine(a );

            }

        }


7. Describe the implementation of the indexer in C , whether it can only be indexed by numbers

For:

By providing an indexer, you can work with objects as if you were working with an array. I n particular, properties, each element is exposed in a get or set method. I ndexers can index not only numbers (array substations), but also some HASHMAP strings, so, in general, there is usually only one indexer in the class in C#, which is THIS, but there can also be countless, as long as your list of parameters is different. I ndexers are independent of return values, and the biggest benefit of indexers is that they make the code look more natural and realistic.

An example of Microsoft's official:

The indexer allows instances of a class or structure to be indexed in the same way as an array.

Indexers are similar to properties, except that their accessors take parameters.

In the following example, a generic class is defined and provided with a simple get and set accessor method (as a way to assign and retrieve values). The Program class creates an instance of this class for the storage string.

class SampleCollection<T>

{

    private T[] arr = new T[100];

    public T this[int i]   //注意,定义索引器。this 关键字用于定义索引器。

    {

        get

        {

            return arr[i]; //访问器采用参数

        }

        set

        {

            arr[i] = value; //访问器采用参数

        }

    }

}

// This class shows how client code uses the indexer

class Program

{

    static void Main(string[] args)

    {

        SampleCollection<string> stringCollection = new SampleCollection<string>(); 

        stringCollection[0] = "Hello, World"; //这里 使用索引器进行引用

        System.Console.WriteLine(stringCollection[0]);

    }

}

The indexer allows objects to be indexed in a similar way to arrays.

The get accessor returns a value. T he set accessor assigns a value.

The this keyword is used to define the indexer.

The value keyword is used to define the value assigned by the set indexer.

The indexer does not have to index based on integer values, and it is up to you to decide how to define a specific lookup mechanism.

The indexer can be overloaded.

The indexer can have multiple ginsengs, such as when accessing a two-dimensional array.


8. With .net as a B/S structure system, you are using several layers of structure to develop, each layer of the relationship and why so layered?

For:

Layer with MVC mode

Typically, there are three layers: the data access layer, the business layer, the representing layer.

The data access layer adds and censors the database.

Business layer is generally divided into two layers, business surface layer implementation and the communication of the means layer, business rules layer to achieve the security of user passwords.

The representing layer adds forms in order to interact with the user, such as the user.


9. What is boxing and unboxing?

For:

Boxing is the implicit conversion of a value type to a reference object.

Unboxing is converting a reference object to any value type.

Like what:

int i=0;

Syste.Object obj=i;

This process is boxing! I t's boxing the i!

Like what:

int i=0;

System.Object obj=i;

int j=(int)obj;

The first 2 sentences of this process are to box i, and the 2nd sentence is to unbox obj!


10. What is regulated (managed) code?

For:

Managed code is the code that runs the .NET common language runtime CLR.

unsafe: Unmanaged code that does not run through clR, and the programmer allocates and frees up memory space on his own.


11.ADO.net commonly used objects in this application? D escribe it separately.

For:

DataSet: Data set.

DataCommand: Execute statement commands.

DataAdapter: A collection of data, populated with terms.

DataReader: Data reader-only

Connection: Database connection pair

Command: Database command


12. What is Code-Behind technology?

A: Code rear.


13. In .net, what does an accessory mean?

A: The assembly. ( Intermediate language, source data, resources, assembly list)


14. What are the common ways to call WebService?

For:

1. Use the WSDL .exe command line tool.

2. Use VS.NET Web Reference menu options in the menu


15. In C, string str snull and string str s", try to use text or images to illustrate the difference.

For:

String str snull does not allocate memory space for him, while string str s" allocates memory space to an empty string.


16. Please elaborate on the similarity between class and structure (struct) in C?

For:

Class can be instantiated, belongs to a reference type, can implement interfaces and single inheritance of other classes, and can also be used as a base type, is allocated to the heap of memory.

struct is a value type and cannot be used as a base type, but an interface can be implemented and is allocated to the stack of memory.


17. Write out a Sql statement: Take out the 31st to 40th records in Table A (SQLServer, with the auto-growth ID as the primary key, note: the ID may not be continuous.)

For:

Solution 1: select top 10 s from A where id not in (select top 30 id from A)

Solution 2: select top 10 s from A where id sgt; (select max (id) from (select top 30 id from A) as A)


18.GC what is it? W hy a GC?

For:

GC is a garbage collector. P rogrammers don't have to worry about memory management because the garbage collector manages it automatically. T o request garbage collection, you can call one of the following methods:

System.gc()

Runtime.getRuntime().gc()


19.String s = new String("xyz"); H ow many String Objects have been created?

For:

Two objects, one is "xyx" and the other is a reference object s to "xyx".


20.try , there is a return statement, so will the code in the fine after this try be executed, when will it be executed, before or after the return?

For:

will be executed, after the return.


21. The elements in Set are not repeatable, so what is the way to distinguish between duplicates or not? D o you use it with or withquals()? W hat's the difference between them?

For:

The elements in Set are not repeatable, so use the iterator() method to distinguish between duplicates or not. E quals() is the reading of whether two Set are equal.

The equals() and ?methods determine whether the reference value points to the same object equals() being overwritten in the class, so that the true value is returned when the contents and types of the two separate objects match.


22. Talk about the difference between final, final, finalize.

For:

Final: Modifier (keyword), if a class is declared final, means that it can no longer derive new sub-classes and cannot be inherited as a parent class. T herefore, a class cannot be declared both abstract and final. D eclaring variables or methods as final ensures that they are not changed in use. V ariables declared as final must be given an initial value at the time of declaration and can only be read in future references and cannot be modified. M ethods declared final can also be used and cannot be overloaded

finally: Provides a finally block to perform any purges when exceptions are handled. I f an exception is thrown, the matching catch clause executes and the control goes into the final block, if any.

Finalize: Method name. J ava technology allows you to use the finalize() method to do the necessary cleanup before the garbage collector clears objects from memory. T his method is called by the garbage collector when it determines that the object is not referenced. I t is defined in the Object class, so all classes inherit it. S ubses override the finalize() method to organize system resources or perform other cleanup efforts. T he finalize() method is called on the object before the garbage collector deletes it.


23. How do I handle hundreds of thousands of available data?

For:

with stored procedures or transactions. U pdate at the same time when you get the maximum identity: N ote that the primary key is not self-incremental when this method is synth, there will be no duplicate primary key: G etting the maximum identity requires a stored procedure to get.


24. The difference between a process and a thread?

For:

A process is a unit of resource allocation and scheduling by the system; a thread is a unit of CPU scheduling and dispatching, and a process can have multiple threads that share the resources of the process.


25. The difference between a stack and a stack?

For:

Stack: Automatically assigned and released by the compiler. T he variables defined in the function body are usually on the stack.

Heap: Generally released by a programmer. A llocated memory functions such as new and malloc are allocated on the heap.


26. What is the role of static before member variables and member functions?

For:

They are called normal member variables and normal member functions, also known as class member variables and class member functions. U sed to reflect the state of the class. F or example, class member variables can be used to count the number of class instances, and class member functions are responsible for such statistical action.


27. What does GCC mean?

For:

The global assembly cache.


28. What's the difference between DataReader and Dataset?

For

The biggest difference between DataReader and DataSet is that DataReader always uses SqlConnection to operate the database online. A ny action on SqlConnection throws a DataReader exception. B ecause DataReader loads only one data in memory at a time, the memory consumed is very small: B ecause of the speciality and high performance of DataReader. S o DataReader is only in. Y ou can't read the first one after you read it. D ataSet loads data into memory at once. D iscard the database connection. T he database connection is discarded when the read is complete. B ecause DataSet loads all the data into memory. S o compare the consumption of memory. B ut it's more flexible than DataReader. R ows, columns, and data can be added dynamically. The database is back-passed back to update operations.


29. What's the point of using and new keywords in c, please write what you know? U sing instructions and statements new create instances of new hidden methods in the base class.

For:

Using: Introduce namespaces or use unmanaged resources to automate the Dispose method of classes that implement the IDisposable interface after using the object

new: Create a new instance or hide the parent method


30. What is a virtual function? W hat is an abstract function?

For:

Virtual functions: Functions that are not implemented and can be inherited and rewritten by sub-classes. V irtual CallSomeOne();

Abstract function: A function that stipulates that its non-virtual sub-class must be implemented and must be rewritten. p ublic abstract void CallSomeOne();


31.C the difference between property and attribute, what are their uses and what are the benefits of this mechanism?

For:

There are two properties in C#, Property and Attribute,

Property is simple, which is our common get and set, and is primarily used to provide an interface for reading and setting up private and protected variables in a class.

Attribute is a description of the various characteristics of the thing. A nd That's what Attribute did. I t allows you to associate information with the type of C# you define as a label for that type. T his information is arbitrary, that is, it is not determined by the language itself, you are free to establish and associate any type of information. Y ou can use properties to define design-time information and run-time information, or even run-time behavior characteristics. T he key is that this information can not only be taken out by the user as a type of label, it can be recognized by the compiler, as a subsidiary condition at compile time to participate in the compilation of the program. D efine properties: Properties are actually a class derived from the System.Attribute base class. T he System.Attribute class contains several methods for accessing and checking custom properties. Although you have the right to define any class as a property, it is customary to derive a class from System.Attribute


32. The difference between HashMap and Hastable

For:

HashMap is hastable's lightweight implementation (non-thread-safe implementation), and they all complete the Map interface, the main difference being that HashMap allows an empty key value (key), which may be more efficient than Hastable because of non-thread safety


33..NET difference between a woman and a C

For:

. N ET generally refers to the .NET FrameWork framework, which is a platform, a technology.

C is a programming language that can be based on . The application of the NET platform.


34. Is it run() or start () to start a thread?

For:

Starting a thread is a call to the start() method to make the virtual processor represented by the thread operational, which means that it can be scheduled and executed by the JVM. T his does not mean that the thread will run immediately.

The run() method can produce a flag that must exit to stop a thread.


35. Does the array have a legth() method? D oes String have the method of length()

For:

Arrays do not have the legth() method and have the properties of the length. S tring has the method of length().


36. What is the difference between a value type and a reference type? W rite out the sample code for C

For:

Variables based on value types contain values directly. W hen you assign a value type variable to another value type variable, the included value is copied. T his is different from the assignment of a reference type variable, which copies only the reference to the object, not the object itself. A ll value types are implicitly derived from System.ValueType. U nlike reference types, it is not possible to derive new types from value types. H owever, as with reference types, structures can also implement interfaces. U nlike reference types, value types cannot contain null values. H owever, the empty type feature allows null to be assigned to a value type. Each value type has an implicit default constructor to initialize the type's default values.

Value types consist of two main types: structure, enumeration, structure is divided into the following categories: Numeric (numeric) type, integer, floating-point type, decimal, bool, user-defined structure. A variable of a reference type, also known as an object, stores a reference to the actual data. K eywords that declare reference types: class, interface, delegate, built-in reference types: object, string


37.C the interfaces and classes in the 37-year-old.

For:

different: Interfaces cannot be instantiated directly. T he interface does not contain the implementation of the method. I nterfaces, classes, and structures can be inherited from multiple interfaces. H owever, C# only supports single inheritance: classes can inherit implementations from only one base class. C lass definitions can be split between different source files.

Same: Interfaces, classes, and structures can be inherited from multiple interfaces. A n interface is similar to an abstract base class: any non-abstract type that inherits an interface must implement all members of the interface. I nterfaces can contain events, indexers, methods, and properties. A class can implement multiple interfaces.