I have a class (myClass) that contains a private member of the class (currentData of type myData). I have a property (CurrentData) that allows me to "get" this member. I want to allow users to call functions in currentData, but does not allow them to use an external link to it. For instance.
myClass a = new myClass(); // This is OK a.CurrentData.somefunc(); // This is what I dont want myData m = new myData(); m = a.CurrentData; // ... some time passes here... m.someFunc();
Although I understand that they refer to the same object. I do not want the link to be stored outside my class in the inner member, since the inner member could change unexpectedly.
Is it possible? I have been away from C # for so long that I can’t remember how it all works!
No way to do
a.CurrentData.somefunc();
legal but
m = a.CurrentData;
. a.CurrentData.somefunc(); a.CurrentData, somefunc() .
a.CurrentData
somefunc()
, , :
public void DoSomeFuncWithCurrentData() { this.currentData.someFunc(); } myClass a = new myClass(); a.DoSomeFuncWithCurrentData();
"" .
:
-. CurrentData . - , CurrentData:
CurrentData
myClass a = new myClass(); a.SomeFuncOnCurrentData();
, . , ( , ).
. CurrentData GetCurrentData . , "" , , .
GetCurrentData
. MyData . CurrentData , MyData, MyData. , ( ), , .
MyData
. CurrentData :
someFunc
ObjectExpiredException
- , . , .
var currentData = a.CurrentData; currentData.someFunc();
(.. ) . , , , myClass. , someFunc() myClass, () , myClass .
myClass
someFunc()
, , CurrentData, . myClass CurrentData myClass.
Source: https://habr.com/ru/post/1664619/More articles:Equivalent to OS X - unresolved-symbols = ignore-in-object-files - c ++Manipulate: before pseudoword background with jQuery - javascriptBreaded Sonata Admin Icon - symfonyThe easiest way to determine if a model formula has only an interception - rЧто не так с этими определениями seq/pseq? - computer-scienceДобавление ключа из переменной строки (es6) при использовании синтаксиса распространения - javascriptNpm package.json configuration options used for version numbers - npmIonic 2, how to make an ion list, grow from bottom to top? - cssCamelCase string splitting in space separated words in Swift - stringUnable to Receive Incoming Mail with Mailgun - apiAll Articles