-2

I got c# project from my prof.(no i can't ask him) I understand all except marked part in this class. Can someone give me short explanation or link to answer, what that part of code actually do?

class AccessConnection
{
    private OleDbConnection conn;

    public AccessConnection()
    {
        conn = new OleDbConnection();
        conn.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Bata\Desktop\Izvestaj\praksa\praksa\Studenti.accdb";
    }
    public void otvoriKonekciju()
    {
        conn.Open();
    }
    public void zatvoriKonekciju()
    {
        conn.Close();
    }
    /* This is part of code i don't understand
    public OleDbConnection Conn
    {
        get
        {
            return this.conn;
        }
    }
    */
}
Danilo Ivanovic
  • 1,216
  • 1
  • 10
  • 18
  • 2
    What about it don't you understand? – Servy Dec 18 '17 at 19:31
  • 5
    That is called a [property](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties). – Igor Dec 18 '17 at 19:32
  • What that part of code actually do in program? @Servy – Danilo Ivanovic Dec 18 '17 at 19:32
  • In the code you showed us, it's never used. That code makes it available to someone outside the class (which is not a very good idea, IMHO). – Thomas Weller Dec 18 '17 at 19:33
  • The part will return the oledb connection that is created so you can connect to the database and query it – user1 Dec 18 '17 at 19:34
  • 6
    It doesn't do anything at all when its commented out. –  Dec 18 '17 at 19:34
  • @Igor Thanks for link i now understand what it is. – Danilo Ivanovic Dec 18 '17 at 19:35
  • It makes me a little bit sad that your professor is teaching you to create a new class that wraps a connection object so that you can hard code a connection string. Unfortunately that's normal - even in a "real world" environment you have programmers who do unusual things. Bit ćete pametniji od njega. – Scott Hannen Dec 18 '17 at 19:45

1 Answers1

0
public OleDbConnection Conn
{
    get
    {
        return this.conn;
    }
}

is the same as this:

public OleDbConnection GetConn()
{
    return this.conn;
}

but just as a property. It's basicly a normal property, without a setter.

rokkerboci
  • 1,167
  • 1
  • 7
  • 14