Monday, July 26, 2004
Indexers In C#
<modifier> <return type> this [argument list] Where the modifier can be private, public, protected or internal. The return type can be any valid C# types. The 'this' is a special keyword in C# to indicate the object of the current class. The formal-argument-list specifies the parameters of the indexer. The formal parameter list of an indexer corresponds to that of a method, except that at least one parameter must be specified, and that the ref and out parameter modifiers are not permitted. Remember that indexers in C# must have at least one parameter. Other wise the compiler will generate a compilation error.
// C#: INDEXER The indexers in C# can be overloaded just like member functions. The formal parameter list of an indexer defines the signature of the indexer. Specifically, the signature of an indexer consists of the number and types of its formal parameters. The element type is not part of an indexer's signature, nor is the names of the formal parameters. The signature of an indexer must differ from the signatures of all other indexers declared in the same class. C# do not have the concept of static indexers. If we declare an indexer static, the compiler will show a compilation time error. Indexers & Inheritance
//C#: Indexer : Inheritance Indexers & Polymorphism
//C#: Indexer : Polymorphism Abstract Indexers
//C#: Indexer : Abstract Indexers & Properties
|
Friday, July 23, 2004
Seconds since the Unix epoch in C#
public long GetEpochTime()
{
DateTime dtCurTime = DateTime.Now;
DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 8:00:00 AM");
TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);
long epochtime;
epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
return epochtime;
}
With Best Regards,
Mitesh Mehta
miteshvmehta@gmail.com
Thursday, July 22, 2004
Const vs. Readonly in C#
Const vs. readonly in C#
const (Constants) are variables whose values are set at compile time, either
by the programmer or by the compiler... It cannot be modified there after,
so if you need a field whose value is known at compile time and should not
be changed anytime later then you should declare that field as const...
Interesting note is that const fields are static by default and so you do
not need to instantiate a class to access them...
readonly (Read Only) are variables whose values are set at run time, but
only once... The value of such variables are set in the constructors and
cannot be modified there on... These variables are useful when you want the
value of the variable to be fixed but fixed to a value which is known only
at run time... See this is what C# offers... :-)
Now if you need a static variable whose value is known only at runtime then
make it static readonly... :-)
Mitesh Mehta
Thursday, July 08, 2004
Integration and Patterns online @ MSDN
Integration and Patterns online @ MSDN
Integrations and Patterns, a Patterns and Practices Group publication, is up on the MSDN site.
18 common (?) integration patterns and implementation examples.
Rgds,
Varad.
Static Members of a class
Static Members of a class
A static member of a class can be accessed without creating an instance of
the class... Everyone knows this right!! so what's next...??
A static member cannot be marked as abstract or virtual, trying to do so
will result into an error...
Inside a static member you cannot call any non-static member, trying to do
so will also result in an error...
regards,
Mitesh Mehta