Sunday, July 31, 2011

Technical guidelines for .net programming


1) Avoid parameters
When you call any method in the C# language that was not in-lined, the runtime will actually physically copy the variables you pass as arguments to the formal parameter slot memory in the called method. It causes stack memory operations and incurs a performance hit. It is faster to minimize arguments, and even use constants in the called methods instead of passing them arguments.

2) Avoid local variables
When you call a method in your C# program, the runtime allocates a separate memory region to store all the local variable slots. This memory is allocated on the stack even if you do not access the variables in the function call. Therefore, you can call methods faster if they have fewer variables in them.

3) Use arrays
In the .NET Framework, you have many options for collections, such as the List type, and various other types such as ArrayList. While these types are convenient and should be used when necessary, it is always more efficient to use a simple array if this is possible. The reason for this is that the more complex collections such as List are actually composed of internal arrays. They add logic to avoid the burden of managing the array size on each use. However, if you do not need this logic, or can adjust your code so that the logic is not needed, using an array will be faster.

4) Use StringBuilder
If you are doing significant appending of strings using the C# language, the StringBuilder type can improve performance. This is because the string type is immutable and cannot be changed without reallocating the entire object. Sometimes, using strings instead of StringBuilder for concatenations is faster; this is typically the case when using very small strings or doing infrequent appends.

5) Use static fields
Here, we note that static fields are faster than instance fields, for the same reason that static methods are faster than instance methods. When you load a static field into memory, you do not need the runtime to resolve the instance expression. Loading an instance field must have the object instance first resolved. In fact, even in an object instance, loading a static field is faster because no instance expression instruction is ever used.

6) Comparing Non-Case-Sensitive Strings

In an application sometimes it is necessary to compare two string variables, ignoring the cases. The tempting and traditionally approach is to convert both strings to all lower case or all upper case and then compare them, like such:
str1.ToLower() == str2.ToLower()

However repetitively calling the function ToLower() is a bottleneck in performace. By instead using the built-in string.Compare() function you can increase the speed of your applications.

To check if two strings are equal ignoring case would look like this:

string.Compare(str1, str2, true) == 0 //Ignoring cases
The C# string.Compare function returns an integer that is equal to 0 when the two strings are equal.

7) Use && and || operators

When building if statements, simply make sure to use the double-and notation (&&) and/or the double-or notation (||), (in Visual Basic they are AndAlso and OrElse).

If statements that use & and | must check every part of the statement and then apply the "and" or "or". On the other hand, && and || go thourgh the statements one at a time and stop as soon as the condition has either been met or not met.

Executing less code is always a performace benefit but it also can avoid run-time errors, consider the following C# code:

if (object1 != null && object1.runMethod())
If object1 is null, with the && operator, object1.runMethod()will not execute.
If the && operator is replaced with &, object1.runMethod() will run even if object1 is already known to be null, causing an exception.

8)Lazy Instantiation/Initialization

The Singleton design pattern is often used to provide a single global instance of a class. Sometimes it's the case that a particular singleton won't be needed during an application run. It's generally good practice to delay the creation of any object until it's needed, unless there's a specific need to the contrary - for instance, to pre-cache slow-initializing objects such as database connections. The "double-checked locking" pattern is useful in these situations, as a way to avoid synchronization and still ensure that a needed action is only performed once. Lazy initialization is a technique that can enhance the performance of an entire application through object reduction.


9)Working with Objects and Value Types

Objects are expensive to use, partly because of the overhead involved in allocating memory from the heap (which is actually well-optimized in .NET) and partly because every created object must eventually be destroyed. The destruction of an object may take longer than its creation and initialization,especially if the class contains a custom finalization routine. Also, the garbage collector runs in an indeterministic way; there's no guarantee that an object's memory will be immediately reclaimed when it goes out of scope, and until it's collected, this wasted memory can adversely affect performance.

It's necessary to understand garbage collection to appreciate the full impact of using objects. The single most important fact to know about the garbage collector is that it divides objects into three "generations": 0, 1, and 2. Every object starts out in generation 0; if it survives (if at least one reference is maintained) long enough, it goes to 1; much later, it transitions to 2. The cost of collecting an object increases with each generation. For this reason, it's important to avoid creating unnecessary objects, and to destroy each reference as quickly as possible. The objects that are left will often be long-lived and won't be destroyed until application shutdown.

10) Using the 'Sealed' Keyword
Wherever extensibility is not required, you should use the sealed keyword. This makes your design easier to understand, as someone can tell at a glance if a certain class or method isn't meant to be extended or overridden. It also increases the chances that the compiler will inline code.

11) Use Page.IsPostback to avoid unnecessary processing on a round trip.









We collect videos & images from online sites like youtube and some other websites which provide them. And most of the News is also gathered from other online websites. Any material downloaded or otherwise obtained through the use of the service is done at your own discretion and risk and that you will be solely responsible for any damage to your computer system or loss of data that results from the download of any such material. If you feel that the content on the site is illegal or Privacy please contact us at srinuchalla@gmail.com and such videos, images or any Content will be removed with immediate effect.

What jQuery Does??










We collect videos & images from online sites like youtube and some other websites which provide them. And most of the News is also gathered from other online websites. Any material downloaded or otherwise obtained through the use of the service is done at your own discretion and risk and that you will be solely responsible for any damage to your computer system or loss of data that results from the download of any such material.If you feel that the content on the site is illegal or Privacy please contact us at srinuchalla@gmail.com and such videos, images or any Content will be removed with immediate effect.

Tuesday, March 29, 2011

Using WCF Message Contracts in Operations

Typically when building Windows Communication Foundation (WCF) applications, developers pay close attention to the data structures and serialization issues and do not need to concern themselves with the messages in which the data is carried. For these applications, creating data contracts for the parameters or return values is straightforward. However, sometimes complete control over the structure of a SOAP message is just as important as control over its contents. This is especially true when interoperability is important or to specifically control security issues at the level of the message or message part. In these cases, you can create a message contract that enables you to use a type for a parameter or return value that serializes directly into the precise SOAP message that you need. This topic discusses how to use the various message contract attributes to create a specific message contract for your operation. Using Message Contracts in Operations WCF supports operations modeled on either the remote procedure call (RPC) style or the messaging style. In an RPC-style operation, you can use any serializable type, and you have available to you the features that are available to local calls, such as multiple parameters and ref and out parameters. In this style, the form of serialization chosen controls the structure of the data in the underlying messages, but the WCF runtime creates the messages themselves to support the operation. This enables developers who are not familiar with SOAP and SOAP messages to quickly and easily create and use service applications. The following code example shows a service operation modeled on the RPC style. [OperationContract]public BankingTransactionResponse PostBankingTransaction(BankingTransaction bt); We collect videos & images from online sites like youtube and some other websites which provide them. And most of the News is also gathered from other online websites. Any material downloaded or otherwise obtained through the use of the service is done at your own discretion and risk and that you will be solely responsible for any damage to your computer system or loss of data that results from the download of any such material.If you feel that the content on the site is illegal or Privacy please contact us at srinuchalla@gmail.com and such videos, images or any Content will be removed with immediate effect.

Wednesday, June 23, 2010

Difference between Custom Controls and User Controls.

Difference between Custom Controls and User Controls.

1.User Control is a page file with extension .ascx which can only be used withina single application. But custom controls are assemblies(dll files) that can be used in multiple applications.
2.User Controls cannot be added to the ToolBox of VS.NET . To use a user Control with in anaspx page u have to drag the user Control from the solution Explorer to designer page.But Custom Controls can be added to ToolBox of VS.NET.
3.User Controls can be viewed as a sort of generic controls during the design time.The proper GUI of user controls can be viewed only during the run time.But Custom Controls can be viewed during the design time.
4. User controls are created from existing Webserver and html server controls .But a developer who creates custom controls have to render every thing from the scratch.

Recommendations for Abstract Classes vs. Interfaces

Difference between Interface and abstract class :

The choice of whether to design your functionality as an interface or an abstract class (a MustInherit class in Visual Basic) can sometimes be a difficult one. An abstract class is a class that cannot be instantiated, but must be inherited from. An abstract class may be fully implemented, but is more usually partially implemented or not implemented at all, thereby encapsulating common functionality for inherited classes. For details, see Abstract Classes.
An interface, by contrast, is a totally abstract set of members that can be thought of as defining a contract for conduct. The implementation of an interface is left completely to the developer.
Both interfaces and abstract classes are useful for component interaction. If a method requires an interface as an argument, then any object that implements that interface can be used in the argument.


This method could accept any object that implemented IWidget as the widget argument, even though the implementations of IWidget might be quite different. Abstract classes also allow for this kind of polymorphism, but with a few caveats:

Classes may inherit from only one base class, so if you want to use abstract classes to provide polymorphism to a group of classes, they must all inherit from that class.
Abstract classes may also provide members that have already been implemented. Therefore, you can ensure a certain amount of identical functionality with an abstract class, but cannot with an interface.
Here are some recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components.

If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.




We collect videos & images from online sites like youtube and some other websites which provide them. And most of the News is also gathered from other online websites. Any material downloaded or otherwise obtained through the use of the service is done at your own discretion and risk and that you will be solely responsible for any damage to your computer system or loss of data that results from the download of any such material.If you feel that the content on the site is illegal or Privacy please contact us at srinuchalla@gmail.com and such videos, images or any Content will be removed with immediate effect.

Wednesday, May 19, 2010

WCF related interview Questions

ONLY WCF related Question:

Debugging:
What tools are used for the debugging WCF?
Is it possible to log the messages on the service side? On the client side? How to switch on the logging?
What the difference between the service messages and transport messages?
What the difference between the SoapUi utility and the VS2008 test functionality used for the Web-service testing?
Describe how to use the LoadGen to test WS. What kind of tests?
Configuration files:
Enumerate the high level elements of the section.
What is the name attribute of the element?
What is the contract attribute of the element?
What is the difference in the attributes the binging and the bindingConfiguration of the element?
What is the difference in the attributes the binging and the bindingName of the element?
Are the addresses, the bindings, the contracts unique between services?
How are dependent the app.config and the machine.config files?
Enumerate the high level of the and element.
Service contracts:
Enumerate three message exchange patterns in the WCF model.
If the service operation returns void, what is the message exchange pattern? Is the client waiting the operation to be completed in this case?
What the difference between the request-response pattern and the duplex pattern?
Is the server set up the client address or the client set it up in the duplex communication ? Server uses This address to sent the data back to the client.
Fault contracts:
In what order do we have to catch the exceptions: TimoutException, FaultException, FaultException, CommunicationException?
You are developing WS. Do you have to include the error(s)/success nodes into the response or to use the fault message to handle errors of the WS? What is the difference in these approuches?
WCF versions:
In what version of the .NET was the WCF introduced?
What was the main functionality set for the first version of the WCF?
What new WCF things were in the next versions of the .NET?
Sessions, Instancing, and Concurrency:
Why we need the sessions?
Where session stores the session information? What is the general store for the WCF session?
What is it a correlation? What parameters are mandatory for the correlation?
Who initiate the WCF session, service or a client?
What order are the delivered messages processed in during the session?
How can we create a singleton service?
Does the SessionMode.NotAllowed increase the performance?
What is it the Terminating and Initiating of the OperationContract? Could be the OperationContract Terminating and Initiating at the same time?
How does a client start a session?
Transports:
How to enable streaming?
What types of the operation contract parameters could be streamed?
Do we have to change the maxReceivedMessageSize parameter to use streaming?
What types of the quota have the WCF transports?
What is it the Teredo? How can we use it?
What is it the Net.TCP Port Sharing? How can we use it?
Queues and Reliable Sessions:
What types of reliable messaging are implemented in the WCF?
What is it the Reliable session?
Is the Reliable session asynchronous?
Is the Reliable session tied to the transport session?
Can the Reliable session be established with the one-way, or the request-reply, or with the duplex, or with all those exchange message patterns?
Do the system-provided bindings have the support for the Reliable session and what the binding options are enabled by default?
Reliable sessions in Windows Communication Foundation (WCF) use a transfer window. What is it the Transfer window? What does it means for the sender, for the receiver? How is it depend of the latency?
What is it the Transmission queue and the Target queue? What is the difference?
What is it the Dead-letter queue and the Poison queue? What is the difference?
Could the two-way service operations be used with queued binding?
Could the ExactlyOnce property of the netMsmqBinding be true if the queue is not transactional?
When is the MsmqIntegrationBinding or the NetMsmqBinding used?
Is there an error in the Msmq address the "net.msmq://MyHost/private$/MyQueue"?
Can we use the public queues without the Windows domain? If cannot then why?
Is the MsmqIntegrationBinding used the msmq.formatname scheme or the net.msmq scheme?
Hosting:
What hosting functionality is unique for the Vista OS?
Do we have to use the relative addresses when hosting in the IIS or the absolute addresses? Why?
Could the IIS-hosted WCF service make use of HTTP transport security if the IIS virtual derectory that contains the service does not support it?



We collect videos & images from online sites like youtube and some other websites which provide them. And most of the News is also gathered from other online websites. Any material downloaded or otherwise obtained through the use of the service is done at your own discretion and risk and that you will be solely responsible for any damage to your computer system or loss of data that results from the download of any such material.If you feel that the content on the site is illegal or Privacy please contact us at srinuchalla@gmail.com and such videos, images or any Content will be removed with immediate effect.

Monday, May 3, 2010

Sonata .NET interview Questions

Last week one of my friend attended SONATA Software .NET interview....

Here are the Questions:

1.what is a constructor ?
2.types constructor ?
3.how can we call parameterized constructor from Default constructor & Vice versa.. ?
4.Difference between Interface & Abstract class ?
5.What is WCF ?
6.Difference between WebService & WCF ?
7.Difference between viewstate & Session state ?
8.Difference between delete & truncate ?
9.Difference between virtual & abstract key words?
10.types of variables Private Protected Public
11.How can u swap 2 variables values without using temp variables
12.Types of binding(ploymorphism).
13.Difference between build & rebuild ?
14. Scenario in SQL SERVER :
Emp table with GRADE(A,B,C),SAL,EMPID
Write a single update statement
to add
for A grade 1000 bonus,B 3000, c 5000
u need to write a single statement to upadte the records based on the Grade
15.Difference between Array.Clone & Array.Copy
16.Can we Rollback Truncate ?
Ans :Yes: like this
Write truncate within transaction
Begin Tran
truncate table tablename
ROLLBACK

SONATA INTERVIEW QUESTIONS FOR EXPERIENCED


We collect videos & images from online sites like youtube and some other websites which provide them. And most of the News is also gathered from other online websites. Any material downloaded or otherwise obtained through the use of the service is done at your own discretion and risk and that you will be solely responsible for any damage to your computer system or loss of data that results from the download of any such material.If you feel that the content on the site is illegal or Privacy please contact us at srinuchalla@gmail.com and such videos, images or any Content will be removed with immediate effect.