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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...