当前位置:编程学习 > C#/ASP.NET >>

Hers is some of my search

1. Explain in detail what is wrong with the following code-block and provide a correct implementation:
private string GetString ()
(
string value = string.Empty;

for (int i = 0; i <85000; i + +)
value + = i.ToString ();

return value;
)
[color = # FF0000] Ans> As the string is immutable, whenever value is mmodified, a new string object is created with new value. At the end of loop we have around 85000 string objects unnecesarily.
StringBuilder could be used coz that is mutable. [/ Color]

2. What is the significance of the value 85000 in the code-block above? (Hint: 85,000 bytes and Memory Allocation / Garbage Collection)
[color = # FF0000] Ans> As the number is so high and the string is modified for every loop, so a new object is created every time and that requires bytes and memory allocation. [/ color]

3. You have the following ASP.NET code-behind class:
public partial class Page1: Page
(
private string _value;

public Page1 ()
(
if (DateTime.Now.Ticks% 10 == 0)
_value = "Test";
)

~ Page1 ()
(
if (_value.Equals ( "Test"))
_value = string.Empty;
)
)
You have found events in the Application event log indicating that the ASP.NET worker process is crashing. You determine the problem to be that in some circumstances, accessing _value throws a NullReferenceException. Why does this crash the ASP.NET worker process instead of showing an error to the end-user?
[color = # FF0000] Ans> NullReferenceException depends upon the time at which the Page1 is accessed. If the time Ticks is a multiple of 10 then if statement will be true and 'Test' value will be assigned to _value. But if it is not, then _value will have null value and if this value is accessed by any statement before the destructor is called, this will throw a null value reference exception. [/ color]
4. You have identified that your ASP.NET worker process is consuming large amounts of memory and is not releasing it. How would you identify whether it is a native memory leak or an issue with managed code? If you identified the issue as a problem with managed code, what steps would you take to further isolate the issue?
[color = # FF0000] Ans> The first step that I definitely capable of taking in the right direction is opening Performance Monitor and looking at the values of two important performance counters for my application's process:
•. NET CLR Memory / # Bytes in All Heaps
• Process / Private Bytes
Steps:
• Who allocates what on the managed heap.
• Which objects survive on the managed heap
• Who is holding on to objects.
• What the garbage collector does over the lifetime of your application. [/ Color] Resources: http://blogs.microsoft.co.il/blogs/sasha/archive/2008/07/13/is-it-a-managed -or-a-native-memory-leak.aspx
http://msdn.microsoft.com/en-us/magazine/cc163491.aspx
http://msdn.microsoft.com/en-us/library/ms979205.aspx


5. Provide a comparison of XML and JSON including the pros and cons of each and provide ideal uses for both.
Advantages of JSON:
Simplicity
XML is 易做图r than SGML, but JSON is much 易做图r than XML. JSON has a much smaller grammar and maps more directly onto the data structures used in modern programming languages.
Extensibility
JSON is not extensible because it does not need to be. JSON is not a document markup language, so it is not necessary to define new tags or attributes to represent data in it.
Interoperability
JSON has the same interoperability potential as XML.
Openness
JSON is at least as open as XML, perhaps more so because it is not in the center of corporate / political standardization struggles.

Advantages of XML:
XML is human readable
JSON is much easier for human to read than XML. It is easier to write, too. It is also easier for machines to read and write.
XML can be used as an exchange format to enable users to move their data between similar applications
The same is true for JSON.
XML provides a structure to data so that it is richer in information
The same is true for JSON.
XML is easily processed because the structure of the data is 易做图 and standard
JSON is processed more easily because its structure is 易做图r.
There is a wide range of reusable software available to programmers to handle XML so they don't have to re-invent code
JSON, being a 易做图r notation, needs much less specialized software. In the languages JavaScript and Python, the JSON notation is built into the programming language; no additional software is needed at all. In other languages, only a small amount of JSON-specific code is necessary. For example, a package of three 易做图 classes that makes JSON available to Java is available for free from JSON.org.
XML separates the presentation of data from the structure of that data.
XML requires translating the structure of the data into a document structure. This mapping can be complicated. JSON structures are based on arrays and records. That is what data is made of. XML structures are based on elements (which can be nested), attributes (which cannot), raw content text, entities, DTDs, and other meta structures.
A common exchange format
JSON is a better data exchange format. XML is a better document exchange format. Use the right tool for the right job.
Many views of the one data
JSON does not provide any display capabilities because it is not a document markup language.
Resources: http://www.json.org/xml.html
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,