public class MyClass { public string Name {get; KEYWORD set;} public MyClass(string name) { this.Name = name; } }
Any ideas what KEYWORD is? I searched everything but it was hard to find get / set accessors in google.
If you want to set the value only in the constructor, I would recommend you readonly the keyword:
public class MyClass { private readonly string _name; public MyClass(string name) { _name = name; } public string Name { get { return _name; } } }
The keyword privateallows you to set a property from anywhere in the class:
private
private set;
i.e:
public string Name {get; private set;}
If you also wanted it to be set from the inheritance class, you could use protected.
protected
readonly, , .
readonly
, READONLY .
GenericTypeTea , , , .
, , , , .
, -
public class MyClass { private string name; public string Name {get { return name;} } public MyClass(string nameString) { name = nameString; } }
Source: https://habr.com/ru/post/1762942/More articles:Is it possible to write to the event log contained in a folder using log4net? - log4netВеб-макеты: пиксели против процентов - pixelHow to convert json object to HTML format in java? - javaWSGI event scheduling - pythonJustify the text in the report - c #Pyqt tabs, as in Google Chrome - python.NET Async TcpListener / TcpClient Question - multithreadingNetbeans Platform application installer - netbeans-platformHow can I archive the proc file system? - linuxIs there a way to make the application always start working with Activity1 after using the "Home" button? - javaAll Articles