format output string for Double
June 16, 2009
Sometimes, if you don’t need to understand, just keep it in mind. The output format of type Double is in this case:
- String.Format(“{0:0.00}”, 123.4567); //fixed two digit decimal: “123.46″
- String.Format(“{0:0.##}”, 123.4567); // max two digit decima: “123.46″
- String.Format(“{0:00.0}”, 3.4567); // fixed two digits before point: “03.5″
- String.Format(“{0:0,0.0}”, 12345.67); // thousand separator: “12,345.7″
- String.Format(“{0,10:0.0}”, 123.4567); //positioning: “ 123.5″
- String.Format(“{0,-10:0.0}”, 123.4567); //positioning: “123.5 “
- String.Format(“{0:0aaa.bbb0}”, 12.3); // add in none-digit chars: “12aaa.bbb3″
- …continue later…
what is module?
May 8, 2009
Module is a container for types within an individual assembly.
what is Code Access Security?
May 8, 2009
CAS is a security system that allows administrators and developers to control application authorization similar to the way that they have always beend able to authorize users. The following resources can be controled by authorization:
- file system
- registry
- printers
- event logs
what is delegate?
May 7, 2009
A delegate can be thought of as an object that contains an ordered list of methods with the same signature and return type.
- The list of methods is called the invocation list.
- When a delegate is invoked, it calls each method in its invocation list.
Delegates are types, just as classes are types. And as with classes, a delegate type must be declared before you can create variables and objects of the type.
what is alias directive?
May 7, 2009
using sc = System.Console;
sc is a alias directive. using alias directive allows you to assign an alias for either of the following: a namespace or a type in a namespace.
what are the member access modifiers?
May 7, 2009
- private: Accessible only within the class
- internal: Accessible to all classes within this assembly
- protected: Accessible to all classes derived from this class
- protected internal: Accessible to all classes that are either derived from this class or are declared within this assembly
- public: Accessible to any class
what is the method signature?
May 7, 2009
The signature of a method consists of the following information from the method
header of the method declaration:
- The name of the method
- The number of parameters
- The data types and order of the parameters
- The parameter modifiers
The return type is not part of the signature—although it is a common mistake to believe that it is. The names of the formal parameters are also not part of the signature.
Each overloading method with the same name must have a different signature than the others.
what are the value type and reference type?
May 7, 2009
Value typed data is stored in the stack. Reference typed data will use both: data is stored in the heap and the reference (location) is stored in the stack.
Value types are: sbyte short int long bool byte ushort uint ulong float double char decimal struct enum
Reference types are: object string class interface delegate array
what is the stack and the heap?
May 7, 2009
The stack is an array of memory that acts as a last-in, first-out (LIFO) data structure. It stores several types of data:
- The values of certain types of variables
- The program’s current execution environment
- Parameters passed to methods
The heap is an area where chunks of memory can be allocated to store certain kinds of data. Unlike the stack, memory can be allocated and deallocated from the heap in any order. CLR’s Garbage Collector (GC) automatically cleans up orphaned heap objects when it determines that your code will no longer access them.
Value typed data is stored in the stack. Reference typed data will use both: data is stored in the heap and the reference (location) is stored in the stack.
what is indexer?
May 7, 2009
The underlying data of an indexer is often an array or a collection. Access the object with the indexing operator to get or set the underlying collection. Indexers are a combination of an array and a property. The indexer defines a set and get method for the this reference.
Indexers are fairly typical properties. However, there are some exceptions. Here are some of the similarities and differences between indexers and properties:
-
Indexers can be overloaded.
-
Indexers can be overridden.
-
Indexers can be added to interfaces.
-
Indexers support the standard access modifiers.
-
Indexers cannot be a static member.
-
Indexers are nameless and associated with the this reference.
-
Indexers parameters are indices. Properties do not have indices.
-
Indexers in the base class are accessed as base[indices], while a similar property is accessed base.Property.
The following is an additional example—indexing the two int fields of class Class1.
Class Class1
{
int Temp0; // Private field
int Temp1; // Private field
public int this [ int index ] // The indexer
{
get
{
return ( 0 == index ) // Return value of either Temp0 or Temp1
? Temp0
: Temp1;
}
set
{
if( 0 == index )
Temp0 = value; // Note the implicit variable “value”.
else
Temp1 = value; // Note the implicit variable “value”.
}
}
}
class Example
{
static void Main()
{
Class1 a = new Class1();
Console.WriteLine(“Values — T0: {0}, T1: {1}”, a[0], a[1]);
a[0] = 15;
a[1] = 20;
Console.WriteLine(“Values — T0: {0}, T1: {1}”, a[0], a[1]);
}
}
