Collect some questions in C #

Source: Internet
Author: User
Tags error handling

Collect some C # questions, share them, and learn together.

1. What is the difference between <%#%> and <% %>? The
<%#%> represents a bound data source
<%%> is a server-side code block
2. The following code can be compiled. If not, change to the correct code and explain the reason.
   <%
       int subtract (int num1, int num2) {
          return num1-num2;
      }
  %>
   <body>
      <%
          int number = 100;
         while (number > 0) {
             Response.Write ("Value:" + number + "<br/>");
            number = Subtract (number, 1);
        }
     %>
   </body>

3. What functionality can be implemented through web Site administration Tool (in VS2005). Which files are modified or added automatically by the Web Site administration Tool.

4. Explain the similarities and differences between the data parameter with the "Original_" prefix and the data parameter with no prefixes. (Simple code descriptions are available)

5. Modify the following code snippet so that the GridView can update the data.
<%@ Page language= "C #"%>
<title>GridView</title>
<body>
<form id= "Form1" runat= "Server" >
<asp:gridview id= "GridView1" allowsorting= "true" allowpaging= "true" runat= "Server"
Datasourceid= "SqlDataSource1" datakeynames= "id" autogeneratecolumns= "False" >
<Columns>
<asp:boundfield readonly= "true" headertext= "id" datafield= "id" sortexpression= "id"/>
<asp:boundfield headertext= "Last Name" datafield= "lname" sortexpression= "lname"/>
<asp:boundfield headertext= "The" "Name" datafield= "fname" sortexpression= "FName"/>
</Columns>
</asp:GridView>
<asp:sqldatasource id= "SqlDataSource1" runat= "Server"
Selectcommand= "SELECT [id], [lname], [fname] from [authors]"
connectionstring= "<%$ connectionstrings:pubs%>"/>
</form>
</body>

6. The GridView does not have built-in insert data, and if you want to insert data into the GridView, what do you think?

7. asp.net 2.0 which (some) features you find most exciting. Why. (can also talk about c#2.0)
ASP.net 2.0 highlights 3 ideas in relation to 1.1,
1, increase productivity
A Consistency (masterpage)
B member Management
C data Access
D Personalization
2 Improvement of management capability (e.g. Web.config)
3 Improve performance to meet more people's access

8. What do you think is the biggest difference between asp.net 2.0 (VS2005) and the development tools (. NET 1.0 or others) you used to use. What development ideas (pattern/architecture) You use on previous platforms can be ported to ASP.net 2.0 (or embedded in asp.net 2.0)

1 asp.net 2.0 packs some code, so it's a lot less code than 1.0 of the same functionality.
2 at the same time support code separation and page embedded server-side code two modes, the previous 1.0 version,. NET hints help only in the detached code file, unable to get help hints on the page embedded server-side code,
3 Code and Design interface switch, 2.0 support cursor positioning. I like this one better.
4 in the binding data, do the paging of the table. Update,delete, and other operations can be visualized operation, convenient for beginners
5, added more than 40 new controls in ASP.net, reduced workload


===================


1, override and overloading of the difference
2,. NET error handling mechanism is what
3, C # interface and class similarities and differences
4, the similarities and differences between DataReader and dataset

Override method used to override a parent class that uses a method or operator with the same name to have different types of arguments

The. NET error handling mechanism uses the try->catch->finally structure, and when an error occurs, it is thrown at layers until a matching catch is found.

Interfaces and classes are classes, different things, interfaces contain only the declarations of methods or attributes, the code that does not contain the specific implementation method, the interface can implement multiple inheritance, and the class can only be single inheritance, and the class that inherits the interface must implement the method or property declared in the interface. Interfaces primarily define a specification, a unified invocation method, and interfaces are playing an increasingly important role in large projects.

DataReader is used to read data that the dataset uses to hold data in memory.

The difference between overload and overlay
1. The coverage of the method is the relationship between the subclass and the parent class, and is the vertical relation; The overload of the method is the relationship between the methods in the same class and the horizontal relationship.
2. Coverage can only be caused by one method, or by a pair of methods; The overload of a method is the relationship between multiple methods.
3. The override requires the same parameter list; The overload requires a different parameter list.
4, in the coverage relationship, the call to the method body is based on the object type (object corresponding to the storage space type) to determine the overload relationship, based on the invocation of the actual parameter list and formal parameter list to select the method body.

4, the similarities and differences between DataReader and dataset
The biggest difference between DataReader and DataSet is that DataReader always occupy the SqlConnection and operate the database online. Any action on SqlConnection throws a DataReader exception. Because DataReader only loads one piece of data in memory at a time, the memory footprint is small. Because of the particularity and high performance of DataReader, so DataReader is only in. You can't read the first one after you read the first one.
A dataset is a one-time load of data in memory. Discard database Connections ... The database connection is discarded when read is complete. Because the dataset loads all the data in memory. So it consumes more memory ... But it's more flexible than DataReader. You can dynamically add rows, columns, and data. Return update operation on database ...



===============



A. Fill in the blanks
The ternary operator in 1.c# is _____?
2. When an integer A is assigned to an object, the integer a will be _____?
3. Class Members have _____ forms of accessibility.
4.public static const int a=1; Is there a bug in this code? What is it.
5.float f=-123.567f;
int i= (int) F;
The value of I is now _____?
6. What is wrong with using the operator declaration and declaring only = =?
7. The key word for the declaration is ___?
8. What are the characteristics of a class decorated with sealed?
9. All custom user controls in ASP.net must inherit from ________?
10. All serializable classes in. NET are marked as _____?
11. We don't have to worry about memory leaks in. NET managed code because of the ___?
12. Are there any errors in the following code? _______
Using System;
Class A
{
public virtual void F () {
Console.WriteLine ("A.F");
}
}
Abstract class B:a
{
Public abstract override void F ();
}

13. When class T declares only a private instance constructor, the outside of the program text of T, ___ (may or may not) from T

Derive a new class, ___ (can or may not) directly create any instance of T.
14. What's wrong with the following code?
switch (i) {
Case ():
Casezero ();
Break
Case 1:
Caseone ();
Break
Case 2:
Dufault;
Casetwo ();
Break
}
15. In. NET, class System.Web.UI.Page can be inherited.

Two. Brief answer
1. What is the meaning of using and new in C # Two keywords, please write out what you know.
2. In the following example
Using System;
Class A
{
Public A () {
Printfields ();
}
public virtual void Printfields () {}
}
Class B:a
{
int x=1;
int y;
Public B () {
Y=-1;
}
public override void Printfields () {
Console.WriteLine ("X={0},y={1}", x,y);
}
What output occurs when an instance of B is created using new B ().
3. In the following example

Using System;
Class A
{
public static int X;
Static A () {
x=b.y+1;
}
}
Class B
{
public static int y=a.x+1;
Static B () {}
static void Main () {
Console.WriteLine ("X={0},y={1}", A.X,B.Y);
}
}
What the resulting output is.
4. Talk about the difference between class and structure.
5. A string of length 10000, consisting of 10,000 characters randomly drawn from a-Z. Please write the main thread in the C # language

order to achieve.
6. For one of these enumerated types:
Enum color:byte{
Red,
Green,
Blue,
Orange
}
Try writing a program that shows all the symbol names defined in the enumeration type and their corresponding values.
7. Do you know the design pattern? Please list the name of the design pattern that you know.
8. Design a table in SQL Server to hold a tree-structured org chart (assuming that only the name of the structure diagram

Need to be saved, if I want to query all the positions under a certain position, with a stored procedure to implement, what do you think.
9. What is called SQL injection, how to prevent. Please provide an example.
10. What the following code outputs. Why.
int i=5;
int j=5;
if (Object.referenceequals (I,J))
Console.WriteLine ("Equal");
Else
Console.WriteLine ("Not Equal");


1?:
2 packing
3 3 kinds
4 Const members are static so you should remove the static
5-123
6 to modify both Equale and Gethash ()? Overload "= =" must overload "!="
7 delegate
8 Cannot be inherited
9 System.Web.UI.UserControl
Ten [Serializable]
One GC
The abstract override is not to be decorated together
13 No, you can't.
Case (): no default;
15 Can

The 1 using introduces a name subspace, or automatically invokes its idespose,new after using a pair of pixels to instantiate a

Like, or to modify a method, the table this method completely overrides this method,
2 x=1,y=0
3 x=1,y=2
4 Maximum Difference One is a reference type, one is a value type default member access to public is another difference




=========================================================



. NET & C # Basic Knowledge questions (20%)
1. How to get the handle to the current form or control in. NET (C # or vb.net), especially the handle to the control itself (please enumerate).
Answer: This (C #) Me (vb.net).

2. How to customize messages in. NET (C # or vb.net) and process the messages in the form.
Answer:
Overload the Defwndproc function in the form to handle the message:
protected override void Defwndproc (ref System.WinForms.Message m)
{
Switch (m.msg)
{
Case Wm_lbutton:
String differs from the use of the format function for CString in MFC
String message = String. Format (Receive Message! parameter is: {0},{1} ", M.wparam,m.lparam);
MessageBox.Show (message);///Display a messages box
Break
Case USER:
Code to process
Default
Base. Defwndproc (ref m);///calls the base class function to handle non custom messages.
Break
}
}

3. How to start another program in. NET (C # or vb.net).
Answer: Process

4. How to cancel the closure of a form in. NET (C # or vb.net).
Answer:
private void Form1_Closing (object sender, System.ComponentModel.CancelEventArgs e)
{
E.cancel=true;
}

5. In. NET (C # or vb.net), appplication.exit or Form.close is different.
Answer: One is to exit the entire application, one is to close one of the form

6. In C #, there is a double variable, such as 10321.5, for example, 122235401.21644, how the value of a currency is exported according to the habits of different countries. For example, in the United States with $10,321.50 and $122,235,401.22 and in the United Kingdom is £10 321.50 and £122 235 401.22
Answer:
System.Globalization.CultureInfo myculture = new System.Globalization.CultureInfo ("en-us");
System.Globalization.CultureInfo myculture = new System.Globalization.CultureInfo ("EN-GB");
Decimal y = 9999999999999999999999999999m;
String str = String.Format (myculture, "my amount = {0:c}", y);

7. A password only uses K, L, M, N, O altogether 5 letters, the word in the password arranges from left to right, the password Word must follow the following rule:
(1) The minimum length of the password word is two letters, can be the same, can also be different
(2) K cannot be the first letter of a word
(3) If l appear, the number of occurrences occurs more than once
(4) m can not make the last one can not be the penultimate letter
(5) k appears, then n must appear
(6) O if the last letter, then L must appear
Question one: Which of the following letters can be placed behind the O in Lo, forming a 3-letter password word.
A) K B) L C) M D) N
Answer: B

Question two: If you can get the letter is K, L, M, then the number of two-letter-long password words can be formed.
A) 1 B) 3 (C) 6 D) 9
Answer: A

Question three: Which one of the following is a word password.
A) Klln B) loml C Mllo D) Nmko
Answer: C

8. If the 62-63=1 equation is not valid, move a number (you cannot move the minus sign and equal number) to make the equation set up and how to move.
Answer: 62 move to 2 of the 6-second party


========================


2. In the following example
Using System;
Class A
{
Public A () {
Printfields ();
}
public virtual void Printfields () {}
}
Class B:a
{
int x=1;
int y;
Public B () {
Y=-1;
}
public override void Printfields () {
Console.WriteLine ("X={0},y={1}", x,y);
}
What output occurs when an instance of B is created using new B ().
3. In the following example

Using System;
Class A
{
public static int X;
Static A () {
x=b.y+1;
}
}
Class B
{
public static int y=a.x+1;
Static B () {}
static void Main () {
Console.WriteLine ("X={0},y={1}", A.X,B.Y);
}
}
What the resulting output is.
Can you give me a detailed explanation of these two questions?


==========================


Using System;
Class A
{
Public A () {
Printfields ();
}
public virtual void Printfields () {}
}
Class B:a
{
int x=1;
int y;
Public B () {
Y=-1;
}
public override void Printfields () {
Console.WriteLine ("X={0},y={1}", x,y);
}
What output occurs when an instance of B is created using new B ().

Related Article

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.