Introduction
In C# 7.1 there is no mapping of the values to the variables having automatic properties dynamically. So what happens in mapping values is that the property is able to recogonize the variables and assign the corresponding values to it.
Here in this, I have shown how C# 8.0 can bring the Idea of mapping the values in it. This blog is regarding ideas generated while coding the Set of a class, in which class has a variable declared along the automatic property.
Till the latest version of C# 7.1 launched , this may have not been introduced, as follows.
For example,
There is a class,
- class set
- {
- public string name {get;set;}
- public int flag{ get; set; }
- }
In this class there are two variables with automatic property declared. Now mainly when I am creating a class object set just to have different values, I do this.
- class program
- {
- static void Main(string[] args)
- {
- set[] s = new set[3];
- for (int i = 0; i < 3; i++)
- {
- s[i] ={ "A",1};
-
- }
- }
- }
Explanation
Now above, there is an array of objects created for the class set. So the object s[i] is mapped with values. The mapping is sequential, i.e. s[i] mapping values "A" and 1 with name and falg variable.
If this could be possible then this would increase the effciency of the memory allocation and the program.
And it would be easier to declare the values of the variables having automatic property. But generally we do this,
- s[i].name = "A" ;
- s[i].flag = 1;
Here is the general way of assigning the values to the variables of the class.
So if this would be introduced then it is more helpful.
Summary
So if the dynamic mapping of values can be done it will bring the ease in value declaration as well as a beneficiery for memory allocation. Also it brings the strict rule of assigning value without letting it go unassigned. Also if this would be successful, then Object assigning would happen. Later the idea of template data type will be introduced.