.net will face questions asked of the basic concepts and syntax Series

Last month left, finishing past few days some common interview questions, organized into a series to share with you, is to give the opportunity to those who are prepared, the interview made rockets, work tighten the screws, do not panic, encourage each other.
1.net will face questions asked of the basic concepts of series and grammar
2.net will face questions asked series of object-oriented
3.net will face questions asked series of design patterns
4.net set of interview questions must be asked of the series, exceptions, generics
5.net must face questions to ask a simple algorithm series
6.net will ask questions face series database
7.net will ask questions face of the web front-end series

1. string str null string and the string str = the difference = "" in

string str = "", the object is initialized, and an empty string allocated memory space
string str = null, initialization object does not allocate memory space

2. byte b = 'a'; byte c = 1; byte d = 'ab'; byte e = 'ah'; byte g = 256; this a bit error is wrong then where?

This title examines a size of the data type is capable of carrying data.
b 1byte = 8bit, 1 = 2 characters byte, 1 = English 1 = 8bit byte
C is the so bc, deg wrong. 'a' is a char, A error
d java byte range is -128 to 127, in C # and a byte is 0 to 255

3.string and compare the difference between the StringBuilder, both performance

is a reference type, then the heap allocation
b StringBuilder default capacity is 16, it may be allowed to expand the number of characters in the string package. StringBuffer Each object has a certain buffer capacity, when the size does not exceed the capacity of the string when not allocate new capacity, when the string size exceeds the capacity, the capacity is automatically increased.
c For a simple string concatenation operator, the performance is not always superior to stringbuilder string. Because creating stringbulider object also consumes a lot of performance in string concatenation relatively few cases, excessive abuse stringbuilder lead to a waste of performance rather than save, only a lot of unpredictable number of string manipulation before considering the use of stringbuilder. From the final analysis we can see if it is a relatively small string concatenation do not see much difference.
d Stringbulider use, the best capacity to develop an appropriate value, or the default values frequently than insufficient capacity for memory allocation operations, is inappropriate implementation.
Reference Links: https://www.cnblogs.com/haofuqi/p/4826262.html

4. What is an extension method?

a word interpretation, extension method allows you to "add" methods to existing types without modification type
b conditions: condition must be satisfied by the extended method, a static method must be static class 2. The first parameter type is the type you want to expand, and you need to add this keyword to identify it as an extension method
c advice: typically, only able to achieve an extension method in the case of last resort, and careful implementation
d use: the class name can not be called directly type of call

5.byte a = 255; a + = 5; the value of a is the number?

8 of byte ranges -1 -2 8 th power to 2, -256 to 258, when a + =. 1, a value of 0, when a + = 5, the value of a is 0, a + = 5, the value is 4

6. What is boxing and unboxing?

Packing is implicitly converted into a value type reference type, such as:
int I = 0;
Syste.Object obj = I;
unpacking the reference type is converted into a value type, such as:
int I = 0;
System.Object I = obj;
int J = (int) obj; (unpacking the obj)

7. difference value and reference type
  • Value is a direct type variable containing values. A value assigned to another type of variable type variable value, the value contained in the copy, the default value is 0. Reference type variable assignment copies only references to objects, without copying the object itself, the default value is null
  • Value types are plastic, float, bool, enum. Reference types have class, delegate, Object, string
  • Type values ​​stored on the stack, referenced types are stored in the stack
The role of 8.new keyword
  • Operator: create an object instance
  • Modifier: In the process of defining a derived class of the same name, hide the base class method
  • Constraints: define generic constraints, constraint generic type can be used

    public class ItemFactory where T : IComparable, new()
    {
    }

9. int? What is the difference and int

int? Type to be empty, the default value may be null, int default value is 0, int? Is implemented as a reference type int by packing

10. C # what the delegate is?

Sentence explanation is: the method passed as a parameter to another method parameters.
.net There are many common commissioned as: Func, Action
role: improve the scalability method

11.2 multiplied to calculate the most efficient method 8 equal to a few?

Bit computing is the fastest, using bit arithmetic logic shift << left.
Method 2 << 3 corresponds 0,000,000,000,000,010 (16-bit binary int 2) is left 0,000,000,000,010,000 three (binary 16)
related reference links: https://www.cnblogs.com/zhangmumu/ p / 10781201.html

12.const and readonly What is the difference?

You can identify a constant. The main differences are the following:

1, different initialization position. const must be assigned at the same time declared; readonly That can be assigned in a statement at the can in a static constructor (must be static constructor, general constructor does not work) in the assignment.
2, different modified objects. const i.e. class field may be modified, could also be modified local variables; Readonly only modifies class fields
. 3, const is a compile-time constant, the value is determined at compile time; Readonly run constants, the value is determined at run time.
. 4, const default is static; the static readonly arranged to be displayed if statement
5, different reference types when modified, const reference only modifies string or other types of null value; readonly may be any type.

13. a conventional integer number, please write a method of determining whether the N is an integer power of 2

4 (100) 5 (101), 8 (1000), 16 (10000)
modulo operation:
with number% 2 == 0 can be determined, but this somewhat lower
bit arithmetic logical operation using the bit :( and, two bits are the 1 is 1, the rest are 0, it is determined whether or not equal to 0)
4 & 3 corresponds to 100 & 011, the result is 000 equal to 0, so 4 is an n-th power of 2
5 & 4 corresponds to 101 & 100, a result 100 is not equal to 0, so the power of n 5 is not 2
if you want to ask if N is a power of 2, the N is the number? This is how to count?

 private static byte get(int n)
{
    byte number = 1;
    while (n/2!=1)
    {
        n = n / 2;
        number += 1;
    }
    return number;
}
14.CTS, CLS, CLR are what explanation

CTS: common language system. CLS: Common Language Specification. CLR: the common language runtime.

CTS: Common Type System Common Type System. Int32, Int16 → int, String → string, Boolean → bool. Each language defines its own type, .Net provides a common type by CTS, then translation generates the corresponding .Net type.

CLS: Common Language Specification Common Language Specification. Different different language syntax. Each language has its own grammar, .Net provides a common syntax by CLS, and then generate the corresponding translation in different languages ​​.Net syntax.

CLR: Common Language Runtime Common Language Runtime, is the GC, JIT, etc. these. There are different CLR, such as server CLR, Linux CLR (Mono), Silverlight CLR (CoreCLR). Equivalent to an engine responsible for the implementation of IL.

15. in .net, accessories mean?

Assembly. (Intermediate language, the source data, resources, assembling the list)

16. The analysis of the code below, a, b value is how much?
        string strTmp = "a1某某某";
         int a = System.Text.Encoding.Default.GetBytes(strTmp).Length;
         int b = strTmp.Length;

Analysis: a letter, figure represents a byte, a Chinese accounted occupies two byte, so a = 8, b = 5

17.Strings = new String ( "xyz"); created several String Object?

Two objects, one is "xyz", is a pointer to a referenced object s "xyz" of.

18. foreach traversal can access objects need to implement an interface type or declaration ______ ______ methods.

IEnumerable 、 GetEnumerator

19. The difference between static and non-static members

1. Static member modifier with statis statement, created when the class is instantiated, accessible through class
non-static variables, created when the object is instantiated 2. without statis of variables, accessed through the object,
3. Static The method can not be used in non-static member, non-static method may use a static member
4. The static members belong to the class, but not belong to the object

20.c # possibility of direct manipulation of memory

C # in unsafe mode can refer to for a memory operation, but not the use of pointers in hosted mode, C # the NET default does not run with hands, the need to set up, select the item right -> Properties -> Formation -> " allow unsafe code "tick -> save

21.short s1 = 1; s1 = s1 + 1; there is nothing wrong with short s1 = 1;? S1 + = 1; there anything wrong?

s1 + 1 can not be converted into explicit type short, may be modified to s1 = (short) (s1 + 1). short s1 = 1; s1 + = 1 correctly

22. What is a strongly typed, what is weakly typed? Which is better? why?

Strong typing is to determine the type of data at compile time, the type can not be changed at the time of execution, and weak type will determine the type during execution. No good, two each good, strong type-safe, because it has been determined well in advance, and high efficiency. Compiled for general programming language such as c ++, java, c #, pascal etc., weakly typed contrast insecure, prone to errors at run time, but it is flexible, and more for an interpreted programming language, such as javascript, vb , php, etc.

The role of 23.using keyword

1. reference the namespace
2. Release resources to achieve IDisposiable created using the class, after the end of using custom will call the object's Dispose method to release resources.

What is the difference 24.ref and out

1. types are passed by reference
2. The property is not not be used as variable out, ref argument passing
3.ref parameters must be initialized. out not need to initialize
4. action, when there are a plurality of methods return values, out useful

25.a.Equals (b) and a == b the same?

Not the same, a == b represent only a and b values ​​are equal, a.Equals (b) represents the same a and b

26. The following code evaluator
class Class1
{
    internal static int count = 0;
    static Class1()
    {
        count++;
    }
    public Class1()
    {
        count++;
    }
}
Class1 o1 = new Class1();
Class1 o2 = new Class1();

o1.count value is how much?
Answer: 3, a method of calculating the static configuration, two instances of objects counted twice.

27. With regard to the constructor Which statement is correct?

a) constructor return type can be declared.

b) a private constructor not modified

c) class constructor must be the same name

d) constructor parameters can not
answer: c, a constructor must be the same as the class name, can pass a plurality of transfer, to initialize the object function is to facilitate member, there can be no return type

How much 28.Math.round (11.5) equal? ​​Math.round (-11.5) equals how much?

Inside are 12 c #

29. The difference between & and &&

& Is Bitwise Logical AND operator, such as true & true result is true, 0 & 0 The results are the result of 0,2 & 3 are (10 & 11 = 10) 2
&& is the AND operator, both are true is true
reference links https: // www.cnblogs.com/zhangmumu/p/10781201.html

30. i ++ and ++ i What is the difference?

1.i ++ is the first assignment, then increment; ++ i is the first increment, after the assignment.
2.i = 0, i ++ = 0 , ++ i = 1; Console.WriteLine (++ i == i ++); result bit true

31.float f = 3.4; correct?

Incorrect,. 3.4 type double double precision, double precision downcast float causes deletion (similar to turn long int), it is necessary to cast, float f = 3.4F or float f = (float) 3.4

32. What is the automatic conversion, what is cast, when to automatically convert, when to cast

1. automatic type conversions: Compiler automatically type conversion, no code in the program.
2. cast: force the compiler type conversion, the code must be written in the program
3. conversion rule: from small to large storage region of memory type range type, is automatically converted, as byte => short => int = > long

Guess you like

Origin www.cnblogs.com/zhangmumu/p/11406751.html