About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Don't show

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

The string or System.String Type


 
A String represents an immutable ordered set of characters. The String type is derived from Object, making it a reference type, and therefore, String objects (its array of characters) always live in the heap, never on a thread's stack. The String  type also implements several interface (IComparable/ IComparable<String>, ICloneable, IConvertible, IEnumerable/ IEnumerable<Char>, and IEquatable<String>). The String class is sealed no inheritance allowed.
 
string is an alias for String in the .NET Framework.
 
String object is that it is immutable. That is, once created, a string can never get longer, get shorter, or have any of its characters changed. It allows you  to perform operations on a string without actually changing the string. If you perform a lot of string manipulations, you end up creating a lot of String objects on the heap, which causes more frequent garbage collections, thus hurting your application's performance. To perform a lot of string manipulations efficiently, use the StringBuilder class.

You can concatenate several strings to form a single string by using the C# + (plus) operator:
 
String  sObj=”Hi” + “  “ + “Gentleman”;
 
In this example all strings are literal strings so C# compiler concatenate them at compile time and end up just on string “Hi Gentleman” in the module's metadata. Using the + (plus)  operator on nonliteral strings causes the concatenation to be performed at run time. To concatenate several strings together at run time, avoid using the + operator as it creates multiple string objects on the garbage-collected heap. Instead, use the System.Text.StringBuilder type.


Verbatim Strings (“@”)
C# also offers a special way to declare a string in which all characters between quotes are considered part of the string. These special declarations are called verbatim strings and are typically used when specifying the path of a file or directory or when working with regular expressions. 

// Specifying the pathname of an application 
String file = "C:\\Windows\\System32\\pbrush.exe"; 

// Specifying the pathname of an application by using a verbatim string 
String file = @"C:\Windows\System32\pbrush.exe";

The @ symbol before the string tells the compiler that the string is a verbatim string. In effect, this  tells the compiler to treat backslash characters as backslash characters instead of escape characters.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Ajander Singh on Sunday, October 05, 2008 8:17 PM
Permalink | Comments (0) | Post RSSRSS comment feed

.NET Compiling Process and Manage Code Execution Process


When you compile a program developed in language that target CLR, instead of compiling the source code into machine level code the compiler translate it into intermediate language. No matter which language is used to develop the application, it always gets translated in IL (Intermediate Language). This ensures language interoperability.

  •  In addition to translating the code into IL the compiler also produce the metadata during the process of compilation.
  • The IL and metadata are link an assembly.
  • The compiler creates the .EXE or .DLL file.
  • When you execute the .EXE or.DLL file, the converted into IL and all other relevant information from the base class library is sent to class loader. The class loader loads the code into the memory.
  • Before the code can be executed, the .NET Framework needs to convert IL into native or CPU specific code. The JUST IN TIME (JIT) Compiler translates the code from IL into managed native code. During the process of compilation the JIT compiler compiles only the code that is the required during execution instead of compiling the complete IL code when an uncompelled method is invoked the JIT compiler converts the IL for that method into native code. The process saves time and memory required to convert the complete IL into native code.
  • During JIT compilation the code is also check for type safety. Type safety ensure that objects are always are accessed in a compatible way.
  • After translating the IL into native code, the converted code is sent to the .NET runtime manager.
  • The .NET runtime manager executes the code. While executing the code the security check is performed to ensure the code has appropriate permission for accessing the available resources.


Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Ajander Singh on Monday, September 29, 2008 4:14 AM
Permalink | Comments (0) | Post RSSRSS comment feed