Var keyword in Delphi/Oxygene and C#

I had the privilege of working on some of the interesting languages like Delphi, Oxygene, C# etc.

All the languages listed above has the keyword var which worked slightly different in each of the languages.

In Delphi and Oxygene, one can use var keyword to pass the parameter by reference as well as to start the block of variable initialization within the method.

method MainForm.Function1;

var

message1 : String;

begin

message1 := "Welcome to Ginktage.com";

load(var message1);

MessageBox.Show(message1);

end;

method MainForm.load(var data: String);

begin

data := "This is a test application";

end;

In C#, the var keyword denotes an anonymous type. When you want to assign a variable, you need not specify the type but instead specify it as var, C# finds out what is the resulting type. One of the most common use of the var keyword in C# is in the LINQ query.

Check the 5 Things That You Cannot do with a Local Type Inference In C# to know more about var keyword in C#

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...