Skip to main content

Posts

C# Brainteasers on Using Block

What will be the output of following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JUSTFORFUN {     class Program     {         static void Main(string[] args)         {             using (Student s = new Student())             {                 Console.WriteLine("Insed Using Bock");             }             Console.Read();         }     }     class Student     {              } } Output : Build Error 1 'JUSTFORFUN.Student': type used in a using statement must be implicitly convertible to 'System.IDisposable What it means is, if we need to use any type in using block that t...

using Statement in C#

The following example shows how to use the using statement. C# using (Font font1 = new Font( "Arial" , 10.0f)) { byte charset = font1.GdiCharSet; } Remarks File  and  Font  are examples of managed types that access unmanaged resources (in this case file handles and device contexts). There are many other kinds of unmanaged resources and class library types that encapsulate them. All such types must implement the  IDisposable  interface. As a rule, when you use an  IDisposable  object, you should declare and instantiate it in a  using  statement. The  using  statement calls the  Dispose  method on the object in the correct way, and (when you use it as shown earlier) it also causes the object itself to go out of scope as soon as  Dispose  is called. Within the  using  block, the object is read-only and cannot be modified or reassigned. The  using  sta...

C# Brainteaser (Multiple Catch Blocks For Single Try Block)

What will be output of following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JUSTFORFUN {     class Program     {         static void Main(string[] args)         {             try             {                 int a = 10;                 int b = 0;                 int c = a / b;             }             catch (NullReferenceException ex2)             {                 Console.WriteLine("generic exception with msg :" + ex2.Message);             }             catch (DivideByZeroException...

Object Slicing in C#

Since a lot of folks move into C# from C++, there is an initial tendency of carrying your old baggage of programming fears, gotchas at the back of your mind. Slicing ranks high in this list. Consider the following code class Employee { public: Employee() { }    virtual ~Employee(){ }    virtual void DoWork()  {    cout << "C#, VB.NET, J#" << endl; } }; class Manager : public Employee { public: Manager(){}    virtual ~Manager(){}    void DoWork() {    cout << "Outlook, powerpoint" << endl;    } }; void MakeEveryoneWork( Employee emp , Employee *empPtr, Employee& empRef)  { emp.DoWork();    empPtr->DoWork();    empRef.DoWork();    cout << endl << endl; }   int main(int argc, char* argv[]) {    Employee *emp = new Employee;   ...

Application Pools in IIS

Introduction This article describes the concept of application pools and web garden that has been introduced in IIS 6.0.  I have tried to keep it simple and short, at the same time informative. What is an Application Pool? IIS can isolate an individual Web application or multiple sites into a self-contained process (called an application pool) that communicates directly with the Operating System kernel. What is a Web Garden ? IIS 6.0 worker process isolation modes also enable multiple worker processes to be configured to service requests for a given application pool. This configuration is known as a Web garden. IIS 6.0 Architecture The figure below describes the IIS 6.0 architecture in its simplest form.  Unlike previous versions of IIS, there are multiple processes (application pools) that run independent of each other. The biggest advantage of this (isolation of processes) is, in a shared hosting environment, when one of the web sites goes down because of a ...

What is the difference between Web Farm and Web Garden?

In this blog post, I am going to explain the exact difference between web farm and web garden, and the advantages and disadvantages of using them. I have also described how to create web garden in different version of IIS. Web Farm This is the case where you have only one web server and multiple clients requesting for resources from the same server. But when is huge amount of incoming traffic for your web sites, one standalone server is not sufficient to process the request. You may need to use multiple servers to host the application and divide the traffic among them. This is called “Web Farm”. So when you are hosting your single web site on multiple web servers over load balancer is called “Web Farm”. The below diagram shows the overall representation of Web Farms. In general web farm architecture, a single application is hosted on multiple IIS Server and those are connected with the VIP (Virtual IP) with Load Balancer. Load Balancer IPs are exposed to e...

Introduction to WCF

WCF stands for Windows Communication Foundation. It is Microsoft's latest technology that enables applications in a distributed environment to communicate with each other.WCF is Microsoft's unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing. WCF is an umbrella technology that covers ASMX web services, .NET remoting, WSE, Enterprise Service, and System.Messaging. It is designed to offer a manageable approach to distributed computing, broad interoperability, and direct support for service orientation. WCF supports many styles of distributed application development by providing a layered architecture. ABC of Windows Communication Foundation What are the ABCs of WCF? "ABC" stands for address, binding and contract. Address (Where) It specifies the location of the service means, where the service is hosted. The ...