Friday, August 29, 2014

C# Destructors


Destructors are used to destruct instances of classes.

Following are some key points about C# Destructor:

  1. Destructor in a class must be prefix with the tilde "~" character.
    Ex. If your class name is "MyClass" then it's destructor name should be "~MyClass()

    Sample Program:
    public class MyClass
        {
            public MyClass()
            {
                Console.WriteLine("Constructor");
            }

            ~MyClass()
            {
                Console.WriteLine("Destructor");
            }
        }
  2. A Class can only have one destructor.
  3. Destructors can not defined in structs. 
  4. Destructors can not be overloaded or inherited.
  5. Destructors can not be called. They invoked automatically.
  6. Destructors does not take modifiers or any parameters.
  7. Use destructor only when your class consumes 'unmanaged' resources like files, GDI objects (Bitmap),SQL connection objects.
  8. The destructor implicitly calls 'Finalize' method of the base class object.
  9. Empty destructor should not be used.When a class has destructor, an entry is added in "Finalize" queue. Empty destructor causes loss of performance.
  10. The programmer has no control over when the destructor is called because this is determined by the garbage collector.
Conclusion:

Destructors are not useful in most of the cases. You need to be careful if you are adding destructor in your classes. 
To release resources immediately, you can also choose to implement the dispose pattern and the IDisposable interface. The IDisposable.Dispose implementation can be called by consumers of your class to free unmanaged resources, and you can use the Finalize method to free unmanaged resources in the event that the Dispose method is not called.



I hope this article will help you in understanding C# Destructors.

Thanks & Regards,
Mahesh Bagul







Monday, August 25, 2014

Passed Exam 70-483 Programming in C#

I have taken first step towards MCSD certification and I  passed 70-483 Programming in C# in last month.

I used following books for this exam and it helped me a lot in understanding of few concepts.
  1. Exam Ref 70-483: Programming in C#
  2. MCSD Certification Toolkit (Exam 70-483): Programming in C#

In addition to this, I went through the Programming in C# Jump Start videos. It's really good videos for novice developers. 

Please note that there were few questions that were not at all covered in this book or videos. You may need to use additional resources like MSDN for exam preparation. 
Few resource links are mentioned below:


If you have any questions regarding this exam, please email me on mahesh.bagul@gmail.com

Happy certification.

Thursday, May 26, 2011

Change Windows Registered Owner and Orgnization name

You may need to change the registered user and company name for a Windows O.S. Unfortunately, this process is rather difficult and needs to be done through the registry.
Following the steps will help you to edit the registered user and orgnization name for your Windows computer.


  1. Open 'regedit.exe' through the start menu search box, and then locate the following registry key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
  2. Find the 'RegisteredOwner' and 'RegisteredOrganization' keys in the right-hand pane. Right click on each of these and click on 'Modify'. Change them with new values.


3.To show off the new changes, just type 'winver.exe' into the start menu search box to see the About Windows box.
Regards,
Mahesh Bagul

Tuesday, January 18, 2011

Static Constructor in C#

A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced.

Properties of Static Constructor:
  1. Static constructor can't have access modifiers like Public,Private, Protected.
  2. It does not accept parameters.
  3. A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
  4. A Static constructor can be called directly.
  5. Static constructor can only access static members.
  6. The user has no control on when the static constructor is executed in the program.

Ex:

public class MYStaticClass
{

  // Static constructor:

  static MYStaticClass()
  {
   System.Console.WriteLine("Static constructor called.");
  }

  public static void StaticMethod()
  {
   System.Console.WriteLine("StaticMethod is called.");
  }
}



class TestClass
{
  private void Test()
  {
   // Call to static method.
   MYStaticClass.StaticMethod();

  }

}




//Output:
//Static constructor called.
//StaticMethod is called.



Regards,

Mahesh Bagul

Sunday, January 16, 2011

Vehicle Tracking System in Pune, India

Remote Data Exchange,Pune,India provides GPS based Vehicle Tracking, Personal Tracking solutions.


GPS based Vehicle Tracking System offers an unique way for companies and individuals to monitor and control their cars, jeeps, trucks and other vehicles.  Vehicle Tracking  is applicable in following areas:

  1. Fleet Management
  2. Call Center´s, BPO´s
  3. Courier Services
  4. Public Transport Systems
  5. Taxi and Cool Cab Services
  6. Cash/Jewellery Carrying Vans
  7. Railways
  8. Goods Carrier Companies 
  9. Oil Tankers
  10. Milk Vans
  11. Car Rental and Leasing companies
  12. School Vans
Remote Data Exchange is reputed Vehicle Tracking Company in Pune ,India

Remote Data Exchange,Pune,India provides GPS based Vehicle Tracking, Personal Tracking solutions all over India.

Contact Remote Data Exchange for enquiry.

Address:
Remote Data Exchange,
A1-402, Mahalaxmi Nagar, Mumbai-Bangalore Highway,
Warje, Pune 411 058, Maharashtra, India.

Call:
Mr.Tushar S. Wakde

+91 98224 36151 
+91 20 64700247
Email: tushar@rdxindia.net

Tuesday, January 11, 2011

Learn Expression Blend in 5 days

Hi Friends,

Microsoft provides a very good training session for Expression Blend. Click following link:

Learn Expression Blend in 5 days



Keep smiling

Mahesh Bagul

Wednesday, January 5, 2011

How to install assembly in GAC

Hi friends,

Follow following steps to install assembly in GAC (Global assembly cache) using C# VS 2005/2008 .


  1. In Visual Studio, create a new Visual C# Class Library project, and name the project TestGAC.
  2. To install assembly in GAC, assembly should be strong name. We use SN tool to generate cryptographic key pair. This tool is located in the \bin subdirectory where the .NET Framework Solution Developer Kit (SDK) is installed. Or eaiser way is:
    • In Solution Explorer, right-click GACDemo, and then click Properties.
    • Click the Signing tab, and then click to select the Sign the assembly check box.
    • In the Choose a strong name key list, click .
    • Type Mykey.snk
    • Compile the project.
3.Now you can install your assembly using Gacutil tool.

Ex: gacutil -I "[DriveLetter]:\[PathToBinDirectoryInVSProject]\TestGAC.dll"



That's it.Your assembly is in GAC....

Keep smiling..
Keep programming...

Mahesh Bagul
 
  1. http://support.microsoft.com/kb/815808
  2. http://support.microsoft.com/kb/315682

( Mahesh Bagul )
 Sr. Software Eng. Pune, India.

useful Links: