Skip to main content

Posts

Default Constructors

A default constructor is one with no parameters. If you don't provide one for your class, the compiler will create on default constructor for your class. However if you do provide a constructor with or without any parameters then the compiler doesn't create a default constructor for you.

Implicit Dispose and using statement

In C# you can make sure Dispose is always called for an object, if the object is created within using statment for e.g using(Font onefont = new Font("Courier") { //do something } When the using blocks end, Dispose on the Font will be called automatically. Even if there is exception while creating the object or within the using block, Dispose method will still be called. An implicit finallt block is created for you.

Static in C#

Staic Member: You can access static member through the name of the class in which it is declared. E.g. className.StaticMethod(); You cannot access a static member through the instance of its class. In C# there are no global methods. Static methods are similar to global method but with the advantage that they have access to local members. Equivalent of Static in VB.Net is Shared (and not Static which creates a variable that exists throughout the lifecycle of the program. Also it is not shared among different instance of the class.) For static methods to access the non static methods of the same class, they must create instance of the class. Static Constructor: It is guarnteed to run before the instance of the class is created. You cannot control when it will run though. No access modifiers are allowed on static contructors. You can use initializer instead of static constructor. Static class: useful in creating small utility class holding static methods. Also it makes sure that you dont ...

Copy Constructor

C# doesn't have Copy constructor like C++. Instead it provides ICloneable interface which has Clone method. Class that supports the idea of copy constructor should implement ICloneable interface and then implement Clone method either using Shallow Copy (??) calling MemberwiseClone or Deep copy (??) i.e hand coping all members. Shallow Copy Deep Copy

Microsoft Naming Conventions

Microsoft recommends following naming conventions Variables : use came case e.g. someName Method : use Pascal case e.g. SomeMethod. Also name the method by the action they perform e.g. WriteLine. Microsoft does not recommends Hungarian notation e.g. iSomeInteger or underscore e.g. Some_Integer. Coding standard: Always use this to refer to the members of current class. Never make a member field as public. Always create properties or methods to allow access to member fields.

XML to PDF in .Net

Has anyone used XALAN.Net to generate PDF from XML? It is working fine generating Pdf from FO but I am having problems if I generate FO using XslCompiledTransform to convert XML to FO. The FO file generated by using XslCompiledTransform is different compared to the file generated using XALAN in java. Both are using same style sheet. I am still scratching me head....any tip would be useful. I will post the solution if I can find any... Raj

Resources in ASP.Net

XML resouces provided for Global.asax and web forms. Resource name is webformname.aspx.resx and for Global.asaz it is Global.asax.resx You must add culture specific resources manually as there is no IDE support for this for web forms. Naming convention for culture specific resource is same as in windows application e.g. webformname.culture.resx. If these naming conventions are not followed, resource manager will not be able to find the resources. Main assembly will be deployed in \bin folder with culture specific assemblies beneith it e.g. \bin\en-US, \bin\en.

Resources for Windows Application

Resources are created automatically by default by VS.Net for Windows forms. They can be plain text files for string resources or XML files for string and binary resources. You can select language for each form and have different layout for each language. This creates satiellite assemblies for each language which are used by runtime depending on the culture selected. Each satellite assembly resides in a culture specific folder which uses ISO naming convention for e.g. for UK English it will be en-GB and for US English it would be en-US. There is no code in the resource dll. Main assembly will use resourse dll in sub directories e.g. en-GB\assemblyName.resources.dll. You can add custom resources. Naming convention for custom resource file [resourceType].[culture].resx. This way the culture specific custom resouce files will be compile in the satellite assemblies [undocumented feature]. Resouces files are deployed in \[culture] fodler for windows forms and \bin\[culture] folder for asp.ne...

Setting up ASP.net for Globalization

You can set Globalization using <globalization> element in Machine.Config or Web.Config <globalization culture="en-US" uiCulture="en-US"/> By setting the culture to en-US, a date will be displayed on mm/dd/yyyy format. If we change the culture to en-GB, the date will be displayed as dd/mm/yyyy format. You can set Globalization setting for a specific folder using by using <location> element You can overwrite <globalization> setting by setting culture in <pages> element You can overwrite config setting at runtime.