Calling a method inside an accessor C#
<p>So I have been struggling with this for quite a while. <br>
I am trying to learn OOP but this is so big that it is hard for me at least to understand all of it.<br>
Let's say I have a method in a class that gets something from a database.<br>
This data will be set to a variable.<br>
What I do now is have a public method, call it, and then call the accessor with the value. For example:<br></p>

<pre><code>        private string _name;

        public string Name { get { return _name; } }

        public void MyMethod()
        {
            using (SqlConnection connect = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand("SELECT Name FROM Table WHERE ID = 1", connect))
                {
                    connect.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            _name = Convert.ToString(reader["Name"]);
                        }
                    }
                }
            }
        }
</code></pre>

<p>And I would call it like:</p>

<pre><code>MyClass myclass = new MyClass();
myclass.MyMethod();
string myname = myclass.Name;
</code></pre>

<p>Now this seems really weird to me.<br>
So I thought, maybe it would be worth it to call the method inside the accessor.<br>
Like:<br></p>

<pre><code>public string Name { get { MyMethod(); return _name; } }
</code></pre>

<p>Calling it like:<br></p>

<pre><code>MyClass myclass = new MyClass();
string myname = myclass.Name;
</code></pre>

<p>This would result in less code and I can make my method private.<br>
Yet, I would have trouble doing this when the method has parameters to it.<br>
So how do I do this? Is this bad practice? If this is not how I should do this, then how do I do it?<br></p>

<p>I would really love to hear from you guys! Please don't hesitate to ask questions or make changes to my question.<br>
Also, my sincere apologies if this has been asked already.<br>
Any great tutorials are also really welcome!</p>