O
O
olifem2018-02-22 19:41:19
SQL
olifem, 2018-02-22 19:41:19

What type of data to return from the function when compiling the list?

There is a function that returns a list of data received from the database, what type should it have?

public ??????????????? CreditsList(Credit.MainWindow MainWindow)
        {
            Connection();
            string query = "SELECT * FROM credits";
            SqlCommand command = new SqlCommand(query, connection);
            SqlDataReader reader = command.ExecuteReader();
            List<CreditsList> result = new List<CreditsList>();
            while (reader.Read())
            {
                int credit_id = Convert.ToInt32(reader["credit_id"]);
                string credit_name = Convert.ToString(reader["credit_name"]);
                double credit_percent = Convert.ToDouble(reader["credit_percent"]);
                string credit_info = Convert.ToString(reader["credit_info"]);
                result.Add(new CreditsList(credit_id, credit_name, credit_percent, credit_info));
            }
            reader.Close();
            connection.Close();
            return result;
        }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Bystrov, 2018-02-22
@olifem

Since you return the list result , which you have List<CreditsList>, then I dare to assume that the type of the method should also beList<CreditsList>

F
freeExec, 2018-02-22
@freeExec

Yes, though object, the topic of the question is not disclosed. Why are you not satisfied with the current type?

R
Roman, 2018-02-23
@yarosroman

Use the most general type, if you just need an enumerated type, then IEnumerable, if a list, then IList, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question