One, the blank question
1. The object-oriented language has (inheritance), (encapsulation), (polymorphism).
2. Objects that can be accessed with a foreach traversal need to implement the (IEnumerable) interface or the type of the Declaration (GetEnumerator ()) method.
3. All custom user controls in ASP. NET must inherit from (control).
4. All serializable classes in. NET are marked as ([Serializable]).
5. We don't have to worry about memory leaks in. NET managed code because of the (GC).
6. The keyword that declares a static variable is (static), and the keyword that declares the constant is (const).
7, b/s commonly used structural design model is divided into (model) (view) (Controller). (MVC classic Web/business/dataaccess)
8. The. NET Framework Data provider's 4 core objects (Connection), (Command), (DataReader), (DataAdapter).
Ado. NET 5 objects are commonly used: (Connection), (Command), (DataReader), (DataAdapter), (DataSet).
9, the Main method of command object: (ExecuteNonQuery ()), (ExecuteReader ()), (ExecuteScalar ()).
10. A member of a class: (field), (property), (method).
11. C # delegate keyword (delegate).
Second, simple answer
1. Briefly describe the access rights of private, protected, public, internal, sealed modifiers.
A: Private members are only accessible within the class.
Protected: A protected member that can be accessed within the class and in the inheriting class.
Public: Common members, completely public, without access restrictions.
Internal: can be accessed within the same namespace.
Sealed: Sealed class, class that is decorated with it cannot be inherited.
2, C #, String str = null and string str = "", please try to explain the differences in text.
A: String str = "" Allocates space while string str = NULL does not allocate space.
3. Describe the methods used in. NET to pass parameters between pages, and say their pros and cons.
Answer: Session (ViewState) is simple, but easy to lose.
Application Global.
Cookies are simple, but may not be supported and may be forged.
Input ttype= "Hidden" is simple, may be forged URL parameters simple, displayed in the address bar, the length of a limited database stable, secure, but performance is relatively weak.
4, please briefly describe the common objects in ADO.
A: Connection: A connection that is built on a specific data source.
Command: Executes commands against the data source.
DataReader: Reads a forward-only and read-only stream of data from the data source.
DataAdapter: Populates the DataSet with the data source and resolves the update.
DataSet: A place where data is temporarily stored in the client's memory. It does not deal directly with databases, but through DataAdapter objects and databases.
5. Please outline the main method of command object.
Answer: ExecuteNonQuery (): Used to execute a specified SQL statement, such as update, Insert, Delete, which returns the number of rows affected by the SQL statement.
ExecuteReader (): Executes the query command, returning the DataReader object.
ExecuteScalar (): Returns a single value, such as execution count (*).
6, please briefly describe the DataReader and dataset of the different and same.
A: Dateset can manipulate data while disconnected from the database, bulk manipulate the data, and a dataset (DataSet) is a place where data is temporarily stored in the client's memory. It does not deal directly with databases, but through DataAdapter objects and databases.
Datereader applies To: Read only query results, save memory, improve performance. However, when you use Datereader to read data, they cannot be modified, so it is read-only. And when reading the data, always keep the connection to the database. When using Datereader to read data, the database connection is used, and the close () method must be called to close datereader to perform other operations with the database connection (Connection).
7. Describe the overloads of the method.
A: The overloads of the method support two ways, one is that the parameter is a different type of overload, and the other is an overload with a different number of arguments. In a method overload, only overloads of methods that have different value types are not allowed to be returned.
8. The difference between class and structure.
A: A class is a reference type, and a struct is a value type. The process of converting a value type to a reference type is boxed, and a reference type is converted to a value type called a unboxing.
9. Describe value types and reference types.
A: Value types: Value types are derived from the System.ValueType family, and each value type object has a separate memory area that retains its own value. As long as you modify it in your code, the value is saved within its memory area.
Reference type: The reference type is derived from the System.Object family, which stores a reference to a value, as if the stored object is a balloon, and our reference variable is a line.
The process of converting a value type to a reference type is boxed, and a reference type is converted to a value type called a unboxing.
Value types include: underlying data type (int, long, float, char, BOOL), enum type, struct type. (the basic data type is actually a struct)
Reference types include: classes, interfaces, arrays.
10. The benefits of using generics.
A: One of the primary applications of generics is the generic collection, which can constrain the type of objects it stores and improve the security of the data. The use of elements in the collection without boxing, unpacking, improve the efficiency of the operation.
11, briefly describe the characteristics of the class.
A: encapsulation: To ensure the integrity of the object's own data, security.
Inheritance: Establish the relationship between classes, implement code reuse, and facilitate the expansion of the system.
Polymorphic: The same method invocation can implement different implementations.
12. Describe the differences between abstract methods and virtual methods.
A: Both abstract methods and virtual methods can achieve polymorphism;
Abstract method: Through the abstract keyword declaration. an abstract method does not allow a method body . Methods in abstract classes are not necessarily abstract, and abstract classes can also accommodate specific implementations or methods. However, classes that contain abstract methods are necessarily abstract classes . Abstract classes cannot be instantiated . After a class inherits an abstract class, it must implement an abstract method in the subclass, overriding the abstract method with the Override keyword.
Virtual method: Through the virtual keyword declaration. a virtual method must have a method body . After being inherited, you can override the virtual method in a subclass and override the virtual method with the Override keyword.
13. Brief description of the interface.
A: 1. In C #, a class cannot inherit multiple classes, but it can implement multiple interfaces. 2, interface is a kind of specification and standard. 3, the interface shielding the implementation of the details. 4, the use of the interface to facilitate team collaboration development.
14, what is SQL injection, how to prevent.
A: The so-called SQL injection, by inserting a SQL command into a Web form or entering a query string for a domain name or page request, eventually achieves a malicious SQL command that deceives the server.
1. Never trust the user's input. The user's input can be verified by regular expressions, or by limiting the length, to filter the keywords.
2. Never use dynamically assembled SQL, either using parameterized SQL or directly using stored procedures for data query access.
3. Never use a database connection with administrator rights, and use a separate limited database connection for each app.
4. Do not store confidential information directly, encrypt or hash out passwords and sensitive information.
Third, programming problems
1. Use ADO to insert a data message into the student table.
[CSharp]View PlainCopy
- Using System.Data.SqlClient;
- New Student Information
- Public void Addstudent (String name, int. age)
- {
- //Create Connection object
- string connstring = "Data source=.;i Nitial Catalog=mystudydb; User Id=sa;pwd=sa ";
- SqlConnection connection = new SqlConnection (connstring);
- Connection. Open ();
- //create command object
- String sql = String.Format ("INSERT into Student (studentname,age) VALUES (' {0} ', {1})", name, age);
- SqlCommand command = new SqlCommand (SQL, connection);
- int result = command. ExecuteNonQuery ();
- if (Result > 0)
- {
- Console.WriteLine ("Successful Execution");
- }
- Else
- {
- Console.WriteLine ("Failed execution");
- }
- //Close connection
- Connection. Close ();
- }
2, 1, 1, 2, 3, 5, 8, 13, 21, 34 ... what is the number of 30th digits, which is realized by recursive algorithm.
[CSharp]View PlainCopy
- static void Main (string[] args)
- {
- Fun (30);
- }
- Public static int fun (int n)
- {
- if (n = = 0 | | n = = 1)
- {
- return 1;
- }
- Else
- {
- return Fun (n-1) + fun (n-2);
- }
- }
3, please use bubble method to sort from big to small.
[CSharp]View PlainCopy
- static void Main (string[] args)
- {
- int[] num = {3, 7, 1, 5, 6, 2, 4};
- int temp = 0;
- For (int i = 0; i < Num. Length; i++)
- {
- For (int J = i + 1; j < Num. Length; J + +)
- {
- if (Num[i] < num[j])
- {
- temp = Num[i];
- Num[i] = Num[j];
- NUM[J] = temp;
- }
- }
- }
- }
4, based on the SQL statement paging.
[SQL]View PlainCopy
- SELECT TOP pageSize *
- From table
- WHERE condition
- and ID not in (
- SELECT TOP pageSize * (pageIndex-1) ID
- From table
- WHERE condition ORDER by sort condition
- )
- Order by sort criteria
Transferred from: http://blog.csdn.net/pan_junbiao/article/details/17462763
C # face question