An object-oriented programming language developed by Microsoft that can be used in .NET.
Hi @Sougata Ghosh ,
Thanks for your feedback.
But i dont understand the meaning of this.
See : Mutating Readonly Structs
The code in VB. NET is
Structure Mutable
Private x As Integer
Public Function Mutate() As Integer
x = x + 1
Return x
End Function
End Structure
Module Module1
Public ReadOnly m As Mutable = New Mutable()
Sub Main()
Console.WriteLine(m.Mutate()) ' 1
Console.WriteLine(m.Mutate()) ' 1
Console.WriteLine(m.Mutate()) ' 1
Console.ReadLine()
End Sub
End Module
As the blog points out : accessing a value type gives you a COPY of the value. You get a copy of whatever is presently stored in m. m is immutable, but the copy is not. The copy is then mutated, and the value of x in the copy is returned. But m remains untouched.
Here's another reference you may need:
Why are mutable structs “evil”?
The suggestions in the reference also apply to VB. NET.
Hope them could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.