Tuesday, February 7, 2012

.Net FAQ

-----------------------------------------------------------------------------
C# Frequently Asked Questions
http://blogs.msdn.com/b/csharpfaq/default.aspx?PageIndex=2

------------------------------------------------------------------------------
1. Default access specifier

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.

http://msdn.microsoft.com/en-us/library/ms173121%28v=vs.90%29.aspx

2. Protected Internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

Note:
The protected internal accessibility level means protected OR internal, not protected AND internal. In other words, a protected internal member can be accessed from any class in the same assembly, including derived classes. To limit accessibility to only derived classes in the same assembly, declare the class itself internal, and declare its members as protected.
http://msdn.microsoft.com/en-us/library/ms173121%28v=vs.90%29.aspx

3. Advantages of Delegates

They're a great way of encapsulating a piece of code. For instance, when you attach an event handler to the button, that handler is a delegate. The button doesn't need to know what it does, just how to call it at the right time.

Another example is LINQ - filtering, projecting etc all require the same kind of template code; all that changes is the logic to represent the filter, the projection etc. With lambda expressions in C# 3 (which are converted into delegates or expression trees) this makes it really simple:

var namesOfAdults = people.Where(person => person.Age >= 18)
.Select(person => person.Name);

(That can also be represented as a query expression, but let's not stray too far from delegates.)

Another way of thinking of a delegate is as a single-method interface type. For example, the EventHandler delegate type is a bit like:

public interface IEventHandler
{
void Invoke(object sender, EventArgs e)
}

But the delegate support in the framework allows delegates to be chained together, invoked asynchronously, used as event handlers etc.

http://stackoverflow.com/questions/639320/what-are-the-advantages-of-delegates

4. Function Overloading in webservices

Not Possible for SOAP, Possible in WCF

  [OperationContract(Name = "DoWork")]
        string DoWork();

       [OperationContract(Name = "DoWorkWithParam")]
        string DoWork(string param);

The function overloading in Web Service is not as straightforward as in class. While trying to overload member function, we make two or more methods with the same name with different parameters. But this will not work in web services and will show runtime error because WSDL is not supported by the same method name.

http://www.codeproject.com/Articles/30018/Function-Overloading-in-Web-Services

5.Web services vs WCF
http://msdn.microsoft.com/en-us/library/aa738737.aspx

http://www.codeproject.com/Articles/45698/WCF-Comparison-with-Web-Services-and-NET-Remoting

6. How to consume .net web services from java/python. How dataset will be processed.?
At design time, when the Java developer runs WSDL2Java, there isn't enough information in the schema definition to do anything.Hence, In order for Java developers to consume this Web Service, they'll have to drop down and use their equivalent DOM API directly.
The ultimate solution, however, would be to standardize an XML Schema definition for representing database resultsets that could be supported across all toolkits.


http://msdn.microsoft.com/en-us/magazine/cc188755.aspx


7. Abstract Classes vs. Interfaces
http://msdn.microsoft.com/en-us/library/scsyfw1d%28v=vs.71%29.aspx

8. What is an asax file.
http://msdn.microsoft.com/en-us/library/1xaas8a2%28v=vs.71%29.aspx

9.MutliCast delegates
http://msdn.microsoft.com/en-us/library/ms173175.aspx

10. Sealed Class

The main purpose of a sealed class to take away the inheritance feature from the user so they cannot derive a class from a sealed class. One of the best usage of sealed classes is when you have a class with static members. For example, the Pens and Brushes classes of the System.Drawing namespace.
The Pens class represent the pens for standard colors. This class has only static members. For example, Pens.Blue represents a pen with blue color. Similarly, the Brushes class represents standard brushes. The Brushes.Blue represents a brush with blue color.
So when you're designing your application, you may keep in mind that you have sealed classes to seal user's boundaries.

http://www.c-sharpcorner.com/UploadFile/mahesh/SealedClasses11142005063733AM/SealedClasses.aspx

http://codebetter.com/patricksmacchia/2008/01/05/rambling-on-the-sealed-keyword/

http://www.codeproject.com/Articles/239939/Csharp-Tweaks-Why-to-use-the-sealed-keyword-on-cla

11. Static Classes and Static Class Members
http://msdn.microsoft.com/en-us/library/79b3xss3%28v=vs.80%29.aspx

12.What is the difference between const and static readonly?
http://blogs.msdn.com/b/csharpfaq/archive/2004/12/03/274791.aspx

13.Static Class vs Singleton

What makes you say that either a singleton or a static method isn't thread-safe? Usually both should be implemented to be thread-safe.

The big difference between a singleton and a bunch of static methods is that singletons can implement interfaces (or derive from useful base classes, although that's less common IME), so you can pass around the singleton as if it were "just another" implementation.

http://stackoverflow.com/questions/519520/difference-between-static-class-and-singleton-pattern

14.Primary Interop Assemblies
http://msdn.microsoft.com/en-us/library/aax7sdch.aspx

15.What is SOAP Prootcol

16.Access Modifiers
http://msdn.microsoft.com/en-us/library/wxh6fsc7%28v=vs.71%29.aspx

17. Indexes in SQL
http://www.sqlservercentral.com/articles/Stairway+Series/72284/

18. ExecuteQuery-Vs-ExecuteNonQuery
http://www.dotnetspider.com/forum/98072-ExecuteQuery-Vs-ExecuteNonQuery.aspx

19. ExecuteQuery VS ExecuteReader

20. idictionary
http://msdn.microsoft.com/en-us/library/system.collections.idictionary.aspx

21. Hash table vs. Dictionary

The Dictionary class has the same functionality as the Hashtable class. A Dictionary of a specific type (other than Object) has better performance than a Hashtable for value types because the elements of Hashtable are of type Object and, therefore, boxing and unboxing typically occur if storing or retrieving a value type.
http://msdn.microsoft.com/en-us/library/4yh14awz%28v=vs.80%29.aspx

22. Layered Archtecture and Multitier architecture
The concepts of layer and tier are often used interchangeably. However, one fairly common point of view is that there is indeed a difference, and that a layer is a logical structuring mechanism for the elements that make up the software solution, while a tier is a physical structuring mechanism for the system infrastructure.

http://en.wikipedia.org/wiki/Multitier_architecture


23. Should I use a view, a stored procedure, or a user-defined function

databases.aspfaq.com/database/should-i-use-a-view-a-stored-procedure-or-a-user-defined-function.html

1. A function is a subprogram written to perform certain computations
2. A scalar function returns only a single value (or NULL), whereas a table function returns a (relational) table comprising zero or more rows, each row with one or more columns.
3. Functions must return a value (using the RETURN keyword), but for stored procedures this is not compulsory.
4. Stored procedures can use RETURN keyword but without any value being passed.
5. Functions could be used in SELECT statements, provided they don’t do any data manipulation. However, procedures cannot be included in SELECT statements.
6. A function can have only IN parameters, while stored procedures may have OUT or INOUT parameters.
7. A stored procedure can return multiple values using the OUT parameter or return no value at all.
http://searchsqlserver.techtarget.com/tip/Stored-procedures-vs-functions

We can call a SQL Function from ADO.NET code. Say we havea function named ABC(). So we call as SELECT ABC() from ADO.Net code. We cannot calla directly as ABC().

http://stackoverflow.com/questions/1056390/how-to-use-sql-user-defined-functions-in-net

Reactions:

2 comments: