Selection of Unity interview questions (5)

Hongliu Academy will make you a few steps faster.

I have sorted out some Unity interview questions, hoping to help you.

Interviewer: Which is better between array and List?

answer:

Arrays: Arrays are the first to appear in C#. It is stored contiguously in memory, so the indexing speed is very fast, and the assignment and modification of elements are also very simple. The offset address can be used to access elements, and the time complexity is O(1); the deletion time complexity is O(n), and there is no option to add data to the array.

List: Based on arrays, the time complexity is the same, and insertion is O(n); however, it is similar to an array when there is a small amount of data, and the efficiency will be lower than an array when the data is large.

Interviewer: What is the difference between a hash table and a dictionary?

answer:

Dictionary: Hashtable is used internally as a storage structure.

  • If we try to find a key that doesn't exist, it will return/throw an exception.
  • It's faster than a hashtable because there's no boxing and unboxing, especially for value types.
  • Only public static members are thread-safe.
  • A dictionary is a generic type, which means we can use it with any data type (when creating it, you must specify the data types of both the key and the value).
  • Dictionay is a type-safe implementation of Hashtable, and Keys and Values ​​are strongly typed. The order in which Dictionary traverses the output is the order in which it is added.

Hash table:

  • If we try to find a key that doesn't exist, null is returned.
  • It is slower than a dictionary because it requires boxing and unboxing.
  • All members of the hash table are thread-safe.
  • Hashtables are not a generic type.
  • Hashtable is a loosely typed data structure where we can add any type of key and value.
  • HashTable is optimized, and the objects accessed by subscripts are hashed first, so the interior is hashed out of order.

Interviewer: What is the difference between value types and reference types?

answer:

  • Value type access is fast, reference type access is slow.
  • Value types represent data, and reference types represent pointers and references to data stored in the memory heap.
  • Value types inherit from System.ValueType, and reference types inherit from System.Object.
  • Value types may be stored in both the heap and the stack depending on the declaration location, and reference types are allocated in the heap.

Interviewer: What is serialization?

answer:

Serialization is the process of storing or transferring an object to memory, a database, or a file by converting it into a stream of bytes. The main purpose is to save the state of the object, including the object's data, so that the object can be reconstructed when needed. The reverse process is called deserialization.

Interviewer: What is a delegate, and what is the use of the event keyword?

answer:

A delegate is a class that defines the type of a method so that the method can be passed as a parameter of another method. This method of dynamically assigning methods to parameters can avoid extensive use of If-Else( Switch) statement, while making the program more scalable.

The role of the event keyword is to limit the calling conditions of the delegate so that it can only be performed externally. The -= and += operations cannot be called, but they can be called inside the class.

further reading

Pay attention to the service account of Hongliu Academy and get all the content of this series for free


I'm Dazhi (vx: zhz11235), your technology pathfinder, see you next time!

don't go! Like it , collect it!

OK, you can go.

Guess you like

Origin blog.csdn.net/zhenghongzhi6/article/details/112330537