c # interview questions (2) T questions

 

A. How to invoke the same object in multiple threads, provided that the object will be rewritten once every minute a thread, other threads in the process of rewriting suspend access until the replacement is completed after the visit? (This will not ... have the god please advise)

II. Copy List <ClassA> all elements of lst to another List <ClassA> lst2 objects, there are several ways? What problems will arise after the reference copy using lst2?

 

List <T> object where T is a value type (int type, etc.)

 

The following method can directly copy the values ​​for the type of List:

List<T> oldList =new List<T>();  
oldList.Add(..);  
List<T> newList =new List<T>(oldList);  

List <T> object where T is a reference type (e.g., a custom entity class)

1, for reference types List can not be copied using the above method, it will only copy the List object reference, you can copy the following extension method:

staticclass Extensions  
{  
        publicstatic IList<T> Clone<T>(this IList<T> listToClone) where T: ICloneable  
         {  
                return listToClone.Select(item => (T)item.Clone()).ToList();  
         }  
// <span style = "Color: RGB (0, 0, 0);"> List of course premise is to achieve the objects ICloneable Interface </ span>  
}  

2, the sequence of another embodiment of a deep copy of the referenced object is completed, the most reliable method of this

publicstatic T Clone<T>(T RealObject)  
 
{  
     using (Stream objectStream = new MemoryStream())  
     {  
           // use System.Runtime.Serialization serialization and deserialization complete copy of the object referenced  
             the IFormatter Formatter = new new the BinaryFormatter ();  
             formatter.Serialize(objectStream, RealObject);  
             objectStream.Seek(0, SeekOrigin.Begin);  
            return (T)formatter.Deserialize(objectStream);  
     }  
}  

3, is achieved by using System.Xml.Serialization serialization and deserialization

publicstatic T Clone<T>(T RealObject)  
{   
           using(Stream stream=new MemoryStream()) 
            { 
                XmlSerializer serializer =new XmlSerializer(typeof(T)); 
                serializer.Serialize(stream, RealObject); 
                stream.Seek(0, SeekOrigin.Begin); 
               return (T)serializer.Deserialize(stream); 
            } 

 

The difference between the three WebAPI and WebService

webapi is http protocol, the protocol webservice using a soap
webapi stateless webservice relatively more lightweight. webapi support such as get, post operations such as http

Four three-tier architecture which three? Each doing? What are the advantages and disadvantages?

Three-tier architecture generally includes: a control layer, business logic, data access layer.

1. Database Access Layer (DAL) to the database only CRUD (CRUD) operations, regardless of the result of the operation, regardless of a logical process (such as a user with the same name, the user name is not valid).

2. Business Logic Layer (BLL) does not directly interact with the database, his interaction with the database method is provided by DAL. Before calling these methods, to add their own logic judgment or business processes. In addition the business logic layer (BLL) there may not be to call the DAL method, but perform other business processes.

3. User interface layer (UI) layer that does not call the DAL, he calls the only method provided by the BLL, BLL layer and then decide whether they continue to call the DAL.

advantage:

1. a clear hierarchy, each level provides the interface definition
2. easily replaced with a new implementation to achieve the original level. Sql example, performance optimization, and it does not affect the other layers of the structure of the code. Conducive to post-maintenance.
3. conducive to programming section, reduce the complexity of the business, accelerate the coding efficiency.
4. Each level of clear positioning, content business process clear. Based on the level, it can be divided into different division of labor. Developers can focus on only one layer of which the whole structure.
The interface definition provides a good scalability. For example, switching from a database to mysql oracle, by configuring just switched.
6. Lower between codes, the dependence layers
7. reusability: facilitate reuse code logic layers
8. Security: Interface design requires compliance with the extended development of the principle of a closed modified, enhanced system safety
shortcomings

1. The performance of the system is reduced. An intermediate layer using database access, data conversion and more computation time are required.
2. New business processes, need to increase the functionality of each layer.
3. different levels of interface specifications is not the same level of understanding, resulting in the maintenance of the interface, called the monitoring will affect
4. When a user accesses increases, performance bottleneck.
5 deployment will result in service interruptions
6. After the service hung up, the need to manually timely treatment, cause losses to the user and company

Comparative five EF (the EntityFramework) and the ADO.NET

 

1. higher performance (operating efficiency) Ado.Net performance of some direct use of Command SQLHelper, Connection commands to the database by writing a SQL statement. (EF solid model, the performance will certainly have to lose some !!)

 

2. Convenience (development efficiency) EF easier to use, because developers do not care about how to access the database.

 

3. Applicability: EF for larger projects, some amount of data is large; the Ado.Net small projects (more high efficiency).

 

4. Greater flexibility Ado.Net flexibility, but there may be a problem sql injection.

 

EF are ultimately translated into sql to perform the conversion, the development of very fast. ado relatively speaking, you can handle sql stored procedures and scripts on their own, flexibility, do not need to be translated, but the workload will be relatively more.

 

Microsoft initially quit ORM technology, aimed at improving development efficiency, improve operational efficiency is not, it just makes coding more in line with the database object-oriented programming.

 

EF framework and Ado.Net, in fact, simply put, it is a native of the package and the PK

The difference between six and get the post

 

1.GET data is acquired from the server, POST data is transmitted to the server.

 

2. In the client, GET way through the URL submission of data, the data can be seen in the URL; POST mode, data is placed in the HTML HEADER submitted

 

3. For the GET method, the server acquires the value of the variable with Request.QueryString, for POST method, the server acquires data submitted by Request.Form.

 

4.GET data submission can only have up to 1024 bytes, but this limit is not POST

 

5. The security issues. As in (2) mentioned that when using GET, the parameters will be displayed in the address bar, and POST will not. So, if these data are Chinese data and non-sensitive data, then use the GET; if the user input data is not Chinese characters and contain sensitive data, it is still good to use POST

Seven of the difference between DataSet and DataTable?

DataSet is dataset, DataTable is a data table, storing a plurality DataSet DataTable. DataSet and DataTable like a special container to store data, which can be present when you query the database to get some results.

The difference between eight and stringBuilder string of?

stringbuilder respect string, the efficiency is higher, string can be reassembled memory each time change, the new combination will not stringbuilder, there are additional methods stringbuilder append, insert, replace, etc., more convenient to use.

Nine in the development process if used design patterns? To name a few?

Factory pattern, abstract factory pattern, singleton, observer mode, publish - subscribe model, etc.

Ten foreach inherited from which interface? Do you have to inherit this interface? We must implement the IEnumable Interface 

Eleven EF implement paging, bulk insert data that the most efficient?  

 

.skip (PageSize * PageIndex) .take (PageSize) PageSize is the page size, PageIndex is the current number of pages, bulk insert BulkInsert

How to use twelve AsParallel? How to use AsQueryable?

  var  result = ( from  in  source.AsParallel().WithDegreeOfParallelism(50) select  proc(x)).ToList();
 
Similarities and differences between thirteen and class structure?
Class: class assignment is a reference type instances allocated on the heap in, like just copied reference point to the same segment of memory allocated to the actual object, class has a constructor and destructor, and inherited class can inherit
Structure: type value is allocated on the stack (the stack while the stack access speed is faster, but the stack is put limited resources), the assignment will be assigned structure produce a new object, the structure is not a constructor, but may be added. Structure no destructor, not inherited from another structure or structures inherited, but can be inherited from the same classes and interfaces
Structure and the same class can define fields, methods and constructors, we can instantiate an object
 
Fourteen how to deal with hundreds of thousands of concurrent data?
1. The process can be stored with the tab to tab
2. The first try to filter out all unwanted data
3. multithreaded the Thread
4.ajax asynchronous processing
The improved hardware. You can use the server cluster.
6. caching technology (both hardware and procedures). Visited does not require a secondary access to the database.
 
Fifteen method parameter modifier difference between ref and out of?

1) the address of the variable pass out and ref (reference address), changing the parameter, the argument is also changed. Because they are a reference address;
2) with a ref and out parameters can only be modified to pass variables can not pass constants.
3) of the difference between out and ref
  out modified parameters must be modified in the method, and the ref can not be modified modification;
  out when the incoming parameters, the parameters are local variables, we can not assign, because out will be assigned;
  and the ref modified parameters, the argument must have an initial value can be called in. Because the ref modification does not necessarily give it a value.

The difference between sixteen stack and heap?

1. Application of different ways, the system automatically assigns the stack, the stack open to apply artificial

2. Different sizes, the smaller stack space, heap larger space

3. different application efficiency, fast speed stack, heap slower

4. The memory contents are different, the function call stack, the function first address, then the parameter does not enter the static parameter, the stack is artificially arranged

5. Different bottom, the stack space is continuous, discontinuous heap space

Seventeen talk about the difference between the final, finally, finalize the

can be used to modify final classes, methods, variables, each with a different meaning, represents the final modified class can not inherit expansion, final variables can not be amended, and the final method is not overridden (override).

finally it is a mechanism to ensure that the focus of Java code that must be executed. We can use the try-finally or try-catch-finally close a JDBC connection to similar, to ensure unlock lock operation.

finalize Object base class is a method, which is designed to ensure complete recovery of specific target resource before being garbage collected.

38 The double retrieve Singleton implements a singleton pattern

public class SingletonClass
    {
        private static readonly object _lock = new object();
        private static volatile SingletonClass _instance;
        public static SingletonClass Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_lock)
                    {
                        if (_instance == null)
                        {
                            _instance = new SingletonClass();
                        }
                    }
                }
                return _instance;
            }
        }
        private SingletonClass()
        {
            //your constructor
        }
    }

Please nineteen output program results

 

 static void Main(string[] args)
        {
            you x = 20 ;
            you y = 40 ;
            GetPlus (x, y);
            Console.WriteLine("x=" + x +  "y=" + y);
        }
        public static void GetPlus(  int x,int y) 
        {
            x = x + y;
            and = x + y;
        } 
// X = 60 y = 40 ref changed parameter value refers to a reference, while the constant value of the parameter y

 

static void Main(string[] args)
        {
            Person p1 = new Person();
            Employee p2 = new Employee();
            Person p3 = new Employee();
            Employee p4 = p3 as Employee;
            p1.Foo();
            p1.Act();
            p2.Foo();
            p2.Act();
            p3.Foo();
            p3.Act();
            p4.Foo();
            p4.Act();
        }
       
    }
    public class Person
    {
        public void Foo() 
        {
            Console.WriteLine("f1");
        }
        public virtual void Act() { Console.WriteLine("a1"); }
    }
    public class Employee : Person 
    {
        public void Foo()
        {
            Console.WriteLine("f2");
        }
        public override void Act() { Console.WriteLine("a2"); }
    } 
// F1
// A1
// F2
// a2
// F1
// a2 is overwritten P3 of Acr
// f2 p4 is Employee object
// a2
 static void Main(string[] args)
        {
            string a = "t1";
            Foo(a);
            Console.WriteLine(a);
        }
        static void Foo(string x)
        {
            string y = "t2";
            x = y;
        } 
// t1
 int x = 3 << 1;
 int y = 1 << 2;
 int z = x ^ y;
 Console.WriteLine(x);
 Console.WriteLine(y);
 Console.WriteLine(z);
// 6
// 4
// 2
static void Main(string[] args)
        {
            A a = new B();
            a.Fun();
        }
        public abstract class A
        {
            public A()
            {
                Console.WriteLine('A');
            }
            public virtual void Fun()
            {
                Console.WriteLine("A.Fun()");
            }
        }
            public class B : A
            {
                public B()
                {
                    Console.WriteLine('B');
                }
                public new void Fun()
                {
                    Console.WriteLine("B.Fun()");
                }
            }
// A
// B
// A.Fun()
int i = 2000;
object o = i;
i = 2001 ;
you j = ( you ) o;
Console.WriteLine("i={0},o={1},j={2}", i, o, j); 
// i=2001,o=2000,j=2000

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/carlpeng/p/12102135.html