Idea Of Dynamic Value Assigned To Variable With Automatic Property


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,
  1. class set  
  2.    {  
  3.       public string name {get;set;}  
  4.       public int flag{ get; set; }  
  5.    }  
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.
  1. class program  
  2.    {  
  3.       static void Main(string[] args)  
  4.       {  
  5.          set[] s = new set[3];  
  6.          for (int i = 0; i < 3; i++)  
  7.             {  
  8.                s[i] ={ "A",1};  
  9.                //Here A represents the value of name and 1 represents the value of flag  
  10.             }  
  11.       }  
  12.    }  

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,
  1. s[i].name = "A" ;  
  2. 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.


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.