Posts

Showing posts from January, 2010

System.Environment.NewLine

C# offers the System.Environment.NewLine which acts as "\r\n". The advantage of using the NewLine property is that it is platform sensitive. In Windows, the carriage is represented as "\r\n" where as in Linux, it is "\n". Use System.Environment.NewLine property so that it works correctly on any platform. Example: string str= "Hello" + System.Environment.NewLine + "Sree";

Structs and Constructors.

Did you know that the Value Types ( Structs) cannot have parameterless Constructors? For example the code below generates a compilation error: "Structs cannot contain explicit parameterless constructors" internal struct StructExample { public StructExample() { } } However, you can define parameterless constructors in structs by specifying "static" keyword. internal struct StructExample { static StructExample() { } } No Access modifier is specified, because we "Cannot specify any access modifier for a static Constructor". By Default, they have private access modifier.