ASP.NET interview question collection
1. Briefly describe the access rights of private, protected, public, and internal modifiers.
Answer. private: Private members can only be accessed inside the class.
protected: Protected members, accessible within the class and inherited classes.
public: Public members, completely public, no access restrictions.
internal: Accessible within the same namespace.
2. List several ways to transfer values between ASP.NET pages.
Answer. 1. Use QueryString, such as....?id=1; response. Redirect()....
2. Use Session Variable
3. Use Server.Transfer
3. The rules for a column of numbers are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34.... .. To find out what the 30th digit is, use the recursive algorithm to implement it.
Answer: public class MainClass
{
public static void Main()
{
Console.WriteLine(Foo(30));
}
public static int Foo( int i)
{
if (i <= 0)
return 0;
else if(i > 0 && i <= 2)
return 1;
else return Foo(i -1) + Foo(i - 2);
}
}
4.What is the delegation in C#? Event Is it a kind of delegation?
Answer:
A delegate can substitute one method as a parameter into another method.
A delegate can be understood as a reference pointing to a function.
Yes, it is a special kind of delegation
5. The difference between override and overloading
Answer:
The difference between override and overloading. Overloading is a method with the same name. If the parameters or parameter types are different, multiple overloading is performed to meet different needs.
override is the rewriting of functions in the base class. To adapt to needs.
6. If you need to pass variable values in a system with a B/S structure, but Session, Cookie, and Application cannot be used, how many methods do you have to handle it?
Answer:
this.Server.Transfer
7. Please programmatically traverse all TextBox controls on the page and assign it a value of string.Empty?
Answer:
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is System.Windows.Forms.TextBox)
{
System .Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control;
tb.Text = String.Empty;
}
}
8. Please program to implement one Bubble sortAlgorithm?
Answer:
int [] array = new int
;
int temp = 0;
for (int i = 0; i < array.Length - 1; i++)
{
for (int j = i + 1 ; j < array.Length ; j++)
{
if (array [j] < array [i])
{
temp = array [i] ;
array [i] = array [j] ;
array [j] = temp ;
}
}
}
9. Describe the implementation process of index in C#. Can it only be indexed based on numbers?
Answer: No. Any type can be used.
10. Find the value of the following expression, and write down one or several implementation methods you think of: 1-2+3-4+……+m
answer :
int Num = this.TextBox1.Text.ToString() ;
int Sum = 0 ;
for (int i = 0 ; i < Num + 1 ; i++)
{
if((i%2) == 1)
{
Sum += i ;
}
else
{
Sum = Sum - I ;
}
}
System.Console.WriteLine(Sum.ToString());
System.Console.ReadLine();
11. Use .net to build a B/S structured system. Is it developed using several layers of structure? What is the relationship between each layer and why is it layered like this?
Answer: Generally there are 3 layers
Data access layer, business layer, and presentation layer.
The data access layer performs additions, deletions, checks and modifications on the database.
The business layer is generally divided into two layers. The business appearance layer implements communication with the presentation layer, and the business rule layer implements security of user passwords, etc.
The presentation layer is used to interact with users, such as users adding forms.
Advantages: Clear division of labor, clear organization, easy debugging, and scalability.
Disadvantages: Increased cost.
12. 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 is produced when using new B() to create an instance of B?
Answer: X=1,Y=0;x= 1 y = -1
13. What is an application domain?
Answer: The application domain can be understood as a lightweight process. Play a safety role. It takes up little resources.
14.What are the explanations for CTS, CLS and CLR?
Answer: CTS: Common Language System. CLS: Common Language Specification. CLR: Common Language Runtime.
15.What are boxing and unboxing?
Answer: Convert from value type interface to reference type boxing. Type conversion from reference to value type unboxing.
16.What is regulated code?
Answer: unsafe: unmanaged code. Run without going through the CLR.
17. What is a strong type system?
Answer: RTTI: Type Identification System.
18. What classes are needed to read and write databases in .net? Their role?
Answer: DataSet: data storage.
DataCommand: Execute statement command.
DataAdapter: A collection of data, filled with words.
19.What are the authentication methods of ASP.net? What are the differences?
Answer: 10. Windows (default) uses IIS...From (form) uses account...Passport (key)
20. What is Code-Behind technology?
Answer: Code post-planting.
21.In .net, what does accessories mean?
Answer: Assembly. (Intermediate language, source data, resources, assembly list)
22. What are the commonly used methods of calling WebService?
Answer: 1. Use the WSDL.exe command line tool.
2. Use the Add Web Reference menu option in VS.NET
23.. How does net Remoting work?
Answer: The server sends a process number and a program domain number to the client to determine the location of the object.
24. In C#, string str = null and string str = "" Please try to use text or images to explain the difference.
Answer: string str = null does not allocate memory space to it, but string str = "" allocates memory space with a length of empty string.
25. Please elaborate on the similarities and differences between classes and structures in dotnet?
Answer: Class can be instantiated and is a reference type, which is allocated on the heap of memory. Struct is a value type, which is allocated on the stack of memory.
26. Based on the knowledge of delegate , please complete the following code snippets in the user control:
namespace test
{
public delegate void OnDBOperate();
public class UserControlBase : System.Windows.Forms.UserControl
{
public event OnDBOperate OnNew;
privatevoidtoolBar_ButtonClick(objectsender,System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button.Equals(BtnNew))
{
// Please complete the code below to call the OnNew event signed by the OnDBPerate delegate.
}
}
}
Answer: if(OnNew != null)
OnNew( this, e);
27. Analyze the following code and fill in the blanks
string strTmp = "abcdefgXXXX";
int i= System.Text.Encoding.Default.GetBytes(strTmp).Length;
int j= strTmp.Length;
After the above code is executed , i= j=
Answer: i=13,j=10
28. In the SQLSERVER server, there are two fields ID and LastUpdateDate in the given table table1. ID represents the updated transaction number, LastUpdateDate Indicates the server time at the time of update. Please use a SQL statement to obtain the last updated transaction number
Answer: Select ID FROM table1 Where LastUpdateDate = (Select MAX(LastUpdateDate) FROM table1)
29. According to thread safety Relevant knowledge, analyze the following code, will it cause a deadlock when i>10 when calling the test method? And briefly explain the reason.
public void test(int i)
{
lock(this)
{
if (i>10)
{
i--;
test( i);
}
}
}
Answer: No deadlock will occur, (but one thing is that int is passed by value, so every time it changes, it is just a copy, so there will be no A deadlock occurs. But if int is replaced by an object, a deadlock will occur)
30. Briefly talk about your understanding of remoting and webservice technologies under the Microsoft .NET framework and their practical applications. .
Answer: WS can mainly use HTTP to penetrate firewalls. Remoting can use TCP/IP and binary transmission to improve efficiency.
31. The company requires the development of a component that inherits the System.Windows.Forms.ListView class and requires the following special functions: when clicking on the column header of each column in the ListView, it can be rearranged according to the value of each row of the clicked columnView## All rows in # (sorted in a similar way to DataGrid). Based on your knowledge, please briefly talk about your ideas Answer: According to the clicked column header, the ID of the column is taken out, sorted according to the ID, and then bound to the ListView.
32. Given the following XML file, complete the algorithm flow chart.
< DriverC >
< ;/DriverC>
Please draw a flow chart that traverses all file names (FileName) (please use recursive algorithm).
Answer:
void FindFile( Directory d )
{
FileOrFolders = d.GetFileOrFolders();
foreach( FileOrFolder fof in FileOrFolders )
{
if( fof is File )
You Found a file;
else if ( fof is Directory )
FindFile( fof );
}
}
33. Write a Sql statement: Take out the 31st to 40th records in table A (SQLServer, use the automatically growing ID as the primary key. Note: IDs may not be consecutive.
Answer: Solution 1: select top 10 * from A where id not in (select top 30 id from A)
Solution 2: select top 10 * from A where id > (select max(id) from (select top 30 id from A )as A)
34.
Object-oriented languages have properties, _ properties, and propertiesAnswer: Encapsulation, inheritance, polymorphism.
35. Objects that can be accessed through foreach traversal need to implement interfaces or declare methods.
Answer: IEnumerable, GetEnumerator.
36. What is GC? Why is there a GC?
Answer: The GC is a garbage collector. Programmers don’t have to worry about memory management, because the garbage collector will do it automatically. To manage. To request garbage collection, you can call one of the following methods:
System.gc()
Runtime.getRuntime().gc()
37.String s = new String( "xyz"); How many String Objects were created?
Answer: Two objects, one is "xyx" and the other is a reference object s pointing to "xyx"
38.abstract class and interface. What is the difference?
Answer:
A class that declares the existence of a method without implementing it is called
abstract class (abstract class), which is used to create a class that embodies certain basic behaviors. class and declare a method for that class, but it cannot be implemented in the class. It is not possible to create an instance of the abstract class. However, it is possible to create a variable whose type is an abstract class and have it point to one of the concrete subclasses. Example. There cannot be abstract constructors or abstract static methods. Subclasses of the Abstract class provide implementations for all abstract methods in their parent class, otherwise they would also be abstract classes. Instead, implement the method in a subclass. Other classes that are aware of its behavior can implement these methods in their class. Interface is a variant of abstract class. In an interface, all methods are abstract. Multiple inheritance can be obtained by implementing such an interface. All methods in the interface are abstract and none of them have a program body. Interfaces can only define static final member variables. Implementation of an interface is similar to subclassing, except that the implementing class cannot inherit behavior from the interface definition. When a class implements a particular interface, it defines (i.e. gives the program body to) all of the methods of this interface. It can then call the interface's methods on any object of the class that implements the interface. Since there are abstract classes, it allows using the interface name as the type of the reference variable. Normal dynamic linking will take effect. References can be converted to or from interface types, and instanceof
operator can be used to determine whether an object's class implements the interface. 39. Should you use run() or start() to start a thread?
Answer: To start a thread, call the start() method to make the virtual processor represented by the thread in a runnable state
, which means it can be scheduled and executed by the JVM. This does not mean that the thread will run immediately. The run() method can stop a thread by generating a mustexit flag. 40. Can interfaces inherit interfaces? Can abstract classes implement interfaces? Can abstract classes inherit concrete classes?
Answer: Interfaces can inherit interfaces. Abstract classes can implement interfaces, and whether abstract classes can inherit entity classes, but the premise is that the entity class must have a clear constructor.
41. Can the constructor Constructor be overridden?
Answer: The constructor Constructor cannot be inherited, so Overriding cannot be overridden, but Overloading can be overridden.
42. Can the String class be inherited?
Answer: The String class is a final class and cannot be inherited.
43. There is a return statement in try {}, so will the code in finally {} immediately following this try be executed? When will it be executed, before or after return?
Answer: It will be executed before return.
44. Two objects have the same value (x.equals(y) == true), but they can have different hash codes. Is this correct?
Answer: No, they have the same hash code.
45. Can swtich act on byte, can it act on long, can it act on String?
Answer: switch(expr1), expr1 is a IntegerExpression. Therefore the parameters passed to switch and case statements should be int, short, char or byte. Neither long nor string can be used on switch.
47. When a thread enters a synchronized method of an object, can other threads enter other methods of the object?
No, a synchronized method of an object can only be accessed by one thread.
48. Can the abstract method be static, native, and synchronized at the same time?
Answer: None.
49.Do List, Set, and Map inherit from the Collection interface?
Answer: List, Set are Maps, not Map
50.The elements in Set cannot be repeated, so what should I use? What method is used to distinguish duplication? Should we use == or equals()? What is the difference between them?
Answer: The elements in the Set cannot be repeated, so use the iterator() method to distinguish duplication. equals() determines whether two Sets are equal.
The equals() and == methods determine whether the reference value points to the same object. equals() is overridden in the class in order to return a true value when the contents and types of the two separate objects match.
51.ArrayIs there a length() method? Does String have a length() method?
Answer: Arrays do not have the length() method, but have the attribute of length. String has the length() method.
52. What is the difference between sleep() and wait()?
Answer: The sleep() method is a method that stops the thread for a period of time. After the sleep interval expires, the thread does not necessarily resume execution immediately. This is because at that moment, other threads may be running and are not scheduled to give up execution, unless (a) the "waking up" thread has a higher priority
(b) is running The thread is blocked for other reasons.
wait() is when threads interact. If the thread issues a wait() call to a synchronization object x, the thread will suspend execution and the called object will enter the waiting state until it is awakened or the waiting time expires.
53.Short s1 = 1; s1 = s1 + 1; What’s wrong? short s1 = 1; s1 += 1; What’s wrong?
Answer: short s1 = 1; s1 = s1 + 1; There is an error. s1 is of type short, s1+1 is of type int, and cannot be explicitly converted to type short. It can be modified as s1 =(short)(s1 + 1). short s1 = 1; s1 += 1 is correct.
54. Talk about the difference between final, finally and finalize.
Answer:
final-modifier (keyword) If a class is declared final, it means that it can no longer derive new subclasses and cannot be inherited as a parent class. Therefore, a class cannot be declared both abstract and final. Declare variables or methods as final to ensure that they will not be changed during use. Variables declared as final must be given an initial value when declared, and can only be read in subsequent references and cannot be modified. Methods declared as final can also only be used and cannot be overloaded.
finally-provide a finally block to perform any cleanup operations during exception handling. If an exception is thrown, the matching catch clause is executed and control passes to the finally block (if there is one).
finalize-method name. Java technology allows the use of the finalize() method to do necessary cleanup work before the garbage collector clears the object from memory. This method is called by the garbage collector on this object when it determines that the object is not referenced. It is defined in the Object class, so all classes inherit it. Subclasses override the finalize() method to organize system resources or perform other cleanup work. The finalize() method is called on this object before the garbage collector deletes the object.
55. How to handle hundreds of thousands of concurrent data?
Answer: Use stored procedure or transaction. When the maximum identifier is obtained, it is updated at the same time. Note that the primary key is not in the auto-increment mode. This method will not duplicate the primary key when used concurrently. To obtain the maximum identifier, a stored procedure is required.
56. Are there any major BUGs in Session, and what methods has Microsoft proposed to solve them?
Answer: Due to the process recycling mechanism in iis, the Session will be lost if the system is busy. You can use Sate server or SQL Server database to store the Session. However, this method is slower and cannot capture the END event of the Session.
57. What is the difference between process and thread?
Answer: The process is the unit of resource allocation and scheduling by the system; the thread is the unit of CPU scheduling and dispatch. A process can have multiple threads, and these threads share the resources of the process.
58. What is the difference between heap and stack?
Answer:
Stack: automatically allocated and released by the compiler. Variables defined within a function body are usually on the stack.
Heap: Generally allocated and released by the programmer. What is allocated using memory allocation functions such as new and malloc is on the heap.
59. What is the role of adding static before member variables and member functions?
Answer: They are called constant member variables and constant member functions, also known as class member variables and class member functions. Used to reflect the status of the class respectively. For example, class member variables can be used to count the number of class instances, and class member functions are responsible for such statistical actions.
60.ASP. NET compared with ASP, what are the main improvements?
Answer: asp interpreted form, aspx compiled form, improves performance and helps protect source code.
61. Generate an int array with a length of 100, and randomly insert 1-100 into it, and it cannot be repeated.
int[] intArr=new int[100];
ArrayList myList=new ArrayList();
Random rnd=new Random();
while(myList.Count<100)
{
int num=rnd.Next(1,101);
if(!myList.Contains(num))
myList.Add(num);
}
for(int i=0 ;i<100;i++)
intArr[i]=(int)myList[i];
62. Please explain several commonly used methods of passing parameters between pages in .net, and say Identify their strengths and weaknesses.
Answer: session(viewstate) is simple, but easy to lose
application global
cookie is simple, but may not be supported, and may be forged
input ttype="hidden" is simple, may be forged
The url parameters are simple, displayed in the address bar, and have limited length
The database is stable and safe, but the performance is relatively weak
63. Please indicate the meaning of GAC?
Answer: Global assemblyCache.
64. How many ways are there to send a request to the server?
Answer: get, post. Get is generally a link method, and post is generally a button method.
65.What is the difference between DataReader and Dataset?
Answer: One is a read-only cursor that can only move forward, and the other is a table in memory.
66. How many stages does the software development process generally have? What is the role of each stage?
Answer: Requirements analysis, ArchitectureDesign, code writing, QA, deployment
67. What is the meaning of the two keywords using and new in c#? Please write down your What does it mean to know? The using directive and statement new create an instance new hides methods in the base class.
Answer: using introduces a namespace or uses unmanaged resources
new creates a new instance or hides the parent class method
68. To process a string, first remove the spaces at the beginning and end of the string Remove, if there are consecutive spaces in the middle of the string, only one space is retained, that is, multiple spaces are allowed in the middle of the string, but the number of consecutive spaces cannot exceed one.
Answer: string inputStr=" xx xx ";
inputStr=Regex.Replace(inputStr.Trim()," *"," ");
69. What does the following code output? Why?
int i=5;
int j=5;
if (Object.ReferenceEquals(i,j))
Console.WriteLine("Equal");
else
Console .WriteLine("Not Equal");
Answer: Not equal, because the object is compared
70. What is SQL injection and how to prevent it? Please give an example.
Answer: Use sql keywords to attack the website. Filter keywords' etc.
71. What is reflection?
Answer: Dynamically obtain assembly information
72. How to write using SingletonDesign pattern
Answer: new in static attribute, constructor private
73 .What is Application Pool?
Answer: Web applications, similar to Thread Pool, improve concurrency performance.
74.What is a virtual function? What is an abstract function?
Answer: Virtual function: A function that is not implemented and can be inherited and rewritten by subclasses. Abstract function: A function that stipulates that its non-virtual subclass must be implemented and must be overridden.
75.What is XML?
Answer: XML is extensible markup language. eXtensible Markup Language. Marks refer to information symbols that computers can understand. Through such marks, computers can process articles containing various information. How to define these tags, you can choose an internationally accepted tag language, such as HTML, or you can use a tag language like XML that is freely decided by the relevant people. This is the extensibility of the language. XML is simplified and modified from SGML. It mainly uses XML, XSL and XPath, etc.
76.What is Web Service? UDDI?
Answer: Web Service is a network-based, distributed modular component that performs specific tasks and abides by specific technical specifications. These specifications enable Web Service to interact with other compatible components. Interoperability.
The purpose of UDDI is to establish standards for e-commerce; UDDI is a set of Web-based, distributed, information registration center implementation standards for Web Service, and also includes a set of implementation standards that enable enterprises to provide their own Web Service registration to enable other enterprises to discover the implementation standard of the access protocol.
77.What are user controls in ASP.net?
Answer: User controls are generally used when the content is mostly static, or may change slightly. The use is relatively large. It is similar to include in ASP. But the function is much more powerful.
78. List the XML technology and its applications that you know
Answer: xml is used for configuration and for saving static data types . The most exposed to XML is web services. .and config
79.What are the commonly used objects in ADO.net? Describe each.
Answer: Connection database connection object
Command database command
DataReader data reader
DataSet Data set
80. What is code-Behind technology.
Answer: Files with three suffixes of ASPX, RESX and CS, this is code separation. It realizes the separation of HTML code and server code. It facilitates code writing and organization.
81. What is SOAP and what are it? application.
Answer: simple object access protocol, simple object acceptance protocol. It uses xml as the basic coding structure and is built on existing communication protocols (such as http, but it is said that ms is working on the lowest architecture of soap on tcp/ip) A protocol that standardizes the use of Web Services..
82.The difference between property and attribute in C#, what are their uses, and what are the benefits of this mechanism?
Answer: One is an attribute, used to access fields of a class, and the other is a property, used to identify additional properties of classes, methods, etc.
83. The main difference between XML and HTML
Answer: 1. XML distinguishes between uppercase and lowercase letters, while HTML does not.
2. In HTML, you can omit closing tags such as
The above is the detailed content of ASP.NET interview questions collection. For more information, please follow other related articles on the PHP Chinese website!