Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New dynamic variable in C# 4.0

Tags:

c#

c#-4.0

Can dynamic variables in C# 4.0 be members on a class or passed into or returned from methods? var from C# 3.0 couldn't but I haven't seen any mention anywhere of whether it is possible or not with dynamic.

like image 362
James Newton-King Avatar asked Oct 28 '08 21:10

James Newton-King


People also ask

What are dynamic variables in C?

A dynamic variable can be a single variable or an array of values, each one is kept track of using a pointer. After a dynamic variable is no longer needed it is important to deallocate the memory, return its control to the operating system, by calling "delete" on the pointer. Operation. Symbol.

What is a dynamic variable example?

Dynamic Variable Overview The distinguishing characteristic of a dynamic variable is that its value can change while the application runs. For example, your application might maintain a threshold value that is compared to a field value in each tuple processed.

How do you initialize a dynamic variable?

Dynamic initialization of object refers to initializing the objects at a run time i.e., the initial value of an object is provided during run time. It can be achieved by using constructors and by passing parameters to the constructors.

What is variable dynamic?

Dynamic variables compute their own values by executing statements and logical expressions. A dynamic variable assigns itself the result of a calculation or operation. The dynamic variable types are dynamic string, dynamic number, and dynamic True/False (Boolean).


1 Answers

Yes. There's a big difference between var and dynamic.

var just means "let the compiler infer the real type of the variable".

dynamic is the type of the variable - so anywhere you can specify a type, you can specify dynamic instead, as I understand it. (I'm sure there are some exceptions to this, but that's the basic idea.)

EDIT: Chris Burrow's first blog entry on dynamic (there's a second one already; expect more soon) gives an example class which uses dynamic all over the place.

like image 155
Jon Skeet Avatar answered Oct 04 '22 16:10

Jon Skeet