.NET
•  Greatis •  Security •  AppDatabase •  Utilities •  Delphi/CB • Visual Basic •  just4fun
.NET Software
.NET Components for Visual Studio .NET, Delphi 8, Delphi 2005 and Delphi 2006
 .NET     Entire site
More Info
Delphi to C#
Index

.NET
Form Designer .NET

See also
Delphi VCL software
Visual Basic 6 software
Hot Offer

Form Desigber .Net


  Delphi  

       Constants must be declared before using in special const blocks:
const
  pi = 3.14159265359;
  URL = 'http://www.greatis.com';
This block can be both global declared the unit's interface or implementation part and local declared within the function or procedure:
procedure Dummy;
const
  // this is local constants
  StartValue = 0;
  EndValue = 10;
var
  i: Integer;
begin
  for i:=StartValue to EndValue do // some code here
end;
There are so-called typed constants, but now this feature is obsolete and you have to use initialized variables instead:
// obsolete code:
const
  Start: Integer = 99;
// use it instead:
var
  Start: Integer = 99;
 
 
  C#

There are two related features: const and readonly. Both of them are used as modificators of teh variable declaration.

The const keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable cannot be modified:

class Test
{
   public const double pi = 3.14159265359;
   public const string URL = "http://www.greatis.com";

   void Foo()
   {
      const int x = 1;
   }
};
The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class:
class Test
{
   public readonly int y = 25; // Initialize a readonly field

   public Test() 
   {
      y = 24;   // Initialize a readonly instance field
   }
}
The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants:
class Test
{
   public readonly int y = 25; // Initialize a readonly field
   public const int z = 30;    // Initialize a const field

   public Test()
   {
      // y = 25; // default value
   }

   public Test(int var)
   {
      y = var;  // OK, initialize a readonly field
      z = var;  // Error can't initialize const field
   }
}

Lost features     
Added features Fields can be declarated as readonly. This keyword allows to modify variable value in constructor of the class.
Warnings
Additional information

 
 


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2009 Greatis Software

eXTReMe Tracker