Basic knowledge of C # interview 2

Source: Internet
Author: User

1. C # three-tier architecture

C # Three-tier Architecture Express layer (Ui,user Interface), Business logic layer (BLL businesslogiclayer), data access layer (DAL data access layers). The division of three layers is a physical division. The presentation layer (UI), which is easiest to understand, is the main interface that the user sees. Data access Layer (DAL), it is not difficult to understand, mainly responsible for data deletion and modification. The Business Logic layer (BLL) is a bridge between the presentation layer and the data access layer. The purpose of distinguishing hierarchy is to "high cohesion, low coupling" thought.

2. Basic Database Operations

2.1 Creating a Database

CREATE DATABASE database_name on PRIMARY (name= , FILENAME= "SIZE=, MAXSIZE =, filegrowth=)

2.2 Creating a data table

CREATE TABLE table_name (
Study number int primary key identity,
The name Char(6) is not null,
Professional direction varchar (ten) not null,
Department Code Char(2) not null,
Note varchar ()

2.3 Data Additions

INSERT [INTO] table_name (column_list) VALUES (data_values)

2.4 Data Modification (update)

UPDATE table_name SET  column_name=where

2.5 Deleting data

DELETE table_name WHERE [search_conditions]

2.6 Finding data tables

1, all columns in the output table select*From table_name2, partial column in output table SELECT A,B,C from table_name
3, selecting several records in a table select DISTINCT column name from table_name4, limit the number of rows returned SELECT TOP n from table_name5The basic syntax format for a complete SELECT statement although the complete syntax of the SELECT statement is more complex, its main syntactic format can be summarized as follows: SELECT select_list [into New_table_name] from table_list  [WHERE search_conditions] [GROUP by Group_by_expression]  [Having search_condition] [ORDER by Order_expression [ASC|DESC]]

2.7 Modifying the table structure

Modify table Structure Rename table: exec sp_rename'Old_table_name','new_table_name 'To rename a column:exec sp_rename'Table_name.old_name','new_name','column 'Add a new column: ALTER TABLE [table_name] add [new_column] varchar ( -Change the data type of the column: ALTER TABLE [TABLE_NAME] ALTER COLUMN [COLUMN_NAME] [data_type] Delete column: ALTER TABLE [Table_nam E] Drop column [column_name] Delete tables: DROP TABLE table_name
Delete all data for table: Truncate table [table_name] Create PRIMARY KEY constraint: ALTER TABLE [table_name] ADD constraint PK Primary key clustered (column name) create an external constraint ALTER TABLE [table_name] Add Constra int WZ
Foreign key (column name)
References table name (column name

3. Three paradigms in the database

1. The first paradigm (1NF)

In any relational database, the first paradigm (1NF) is the basic requirement for relational schemas, and a database that does not meet the first normal form (1NF) is not a relational database. The so-called First paradigm (1NF) refers to the fact that each column of a database table is an indivisible basic data item and cannot have multiple values in the same column, that is, an attribute in an entity cannot have multiple values or cannot have duplicate properties. If duplicate attributes are present, you may need to define a new entity, which is composed of duplicate attributes, and a one-to-many relationship between the new entity and the original entity. In the first normal form (1NF), each row of a table contains only one instance of information. For example, for the Employee Information table in Figure 3-2, the employee information cannot be displayed in one column, and two or more of these columns cannot be displayed in one column; Each row in the Employee Information table represents only one employee's information, and the information for an employee appears only once in the table. In short, the first paradigm is a column with no duplicates.

2. Second paradigm (2NF)

The second paradigm (2NF) is established on the basis of the first paradigm (1NF), i.e. satisfying the second normal form (2NF) must first satisfy the first paradigm (1NF). The second normal form (2NF) requires that each instance or row in a database table must be divided by a unique region. For the implementation of the distinction, it is common to add a column to the table to store unique identities for each instance. 3-2 The Employee Information table has the employee number (emp_id) column added because each employee's employee number is unique, so each employee can be uniquely differentiated. This unique attribute column is called the primary key or primary key, and the main code.

The second normal form (2NF) requires that the attributes of an entity depend entirely on the primary key. The so-called full dependency is the inability to have a property that depends only on the primary key, and if so, this part of the property and the primary key should be separated to form a new entity, and the new entity is a one-to-many relationship with the original entity. For the implementation of the distinction, it is common to add a column to the table to store unique identities for each instance. In short, the second paradigm is that a non-principal attribute is dependent on the primary key.

3. The third paradigm (3NF)

Satisfying the third normal form (3NF) must first satisfy the second normal form (2NF). In short, the third paradigm (3NF) requires that a database table not contain non-primary key information already contained in other tables. For example, there is a departmental information table, where each department has a department number (dept_id), a department name, a department profile, and so on. Then in the Employee Information table in Figure 3-2, the department number can no longer be the department name, department profile and other departments related information to join the Employee Information table. If there is no departmental information table, it should be built according to the third paradigm (3NF), otherwise there will be a lot of data redundancy. In short, the third paradigm is that properties do not depend on other non-principal properties.

4. Delegates in C #

4.1 Declaration of Commission

 Public Delegate void MyDelegate (string str);    The //str parameter is the method name,

4.2 Use of Delegates

New mydelegate (C.M1);           If M1 is non-static  , new mydelegate (new C () is required. M1);            D1 (" parameter 1");                         // parameter 1 indicates the parameters used by the C.M1 function
 Public Static void M1 (string  str)               //static belongs to the class but not to the object, {   Console.WriteLine ("from:c.m1:    " , str);}

Note: when delegating declarations (void and string types, the declaration of a delegate is related to a function that requires a delegate)

4.3 Attributes of the delegate

MyDelegate d5 = D1 + d2;          // Combination Properties MyDelegate d6 = d5-d3;          // Delete attribute

5. Events

5.1 Defining event classes

 Public class Testeventargs:eventargs          // Integration Event EventArgs{   publicreadonly Char keytoraiseevent;     Public Testeventargs (char  keytoraiseevent)   {      = keytoraiseevent;   }}

5.2 Declaring event delegates and event objects

 Public Delegate void Testeventhandler (object sender, Testeventargs e);     // Define Delegate  Public Event Testeventhandler testevent;                                   // declaring an Event object with the event keyword

5.3 Event Triggering method

protected  void ontestevent (Testeventargs e)       //Why is the virtual    function {ifnull)        testeven t (  this, e);}

5.4 Event Reference method

 Public void RaiseEvent (char  keytoraiseevent) {      new  Testeventargs (keytoraiseevent);      Ontestevent (e); }

5.5 Listener event Classes

  Public classTesteventlistener {//defines the method that handles the event, which has the same parameters and return value type as the delegate that declares the event         Public voidKeypressed (Objectsender, Testeventsource.testeventargs e) {Console.WriteLine ("sender: {0}, as per health: {1}", sender, e.keytoraiseevent); }        //Subscribe to Events         Public voidSubscribe (Testeventsource evensource) {evensource.testevent+=NewTesteventsource.testeventhandler (keypressed); }        //Unsubscribe Events         Public voidunsubscribe (Testeventsource evensource) {evensource.testevent-=NewTesteventsource.testeventhandler (keypressed); }    }

5.6 Test Event class

 Public classTest { Public Static voidMain () {//Creating an Event source objectTesteventsource es =NewTesteventsource (); //Creating Listener ObjectsTesteventlistener el =NewTesteventlistener (); //Subscribe to EventsConsole.WriteLine ("subscribe to events \ n"); El.            Subscribe (es); //Raising an eventConsole.WriteLine ("Enter a character, and then press the ENTER key"); strings =Console.ReadLine (); Es. RaiseEvent (S.tochararray () [0]); //Unsubscribe EventsConsole.WriteLine ("\ nthe unsubscribe event \ n"); El.            Unsubscribe (es); //Raising an eventConsole.WriteLine ("Enter a character, and then press ENTER"); S=Console.ReadLine (); Es. RaiseEvent (S.tochararray () [0]); }    }

Basic knowledge of C # interview 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.