Bonjour

Je me pose une question sur la meilleure manière de coder le retour d'une "fonction".

Voilà un exemple :

Solution 1 :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
        public void GetConnection(string fileName, out SqliteConnection? sqliteConnection)
        {
            sqliteConnection = new SqliteConnection();
 
            try
            {
                string connectionString = $"Data Source={fileName}";
                SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
                sqliteConnection = new SqliteConnection(connectionString);
            }
            catch
            {
                sqliteConnection = null;
            }
        }
Solution 2 :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
        public SqliteConnection? SqliteConnection2(string fileName)
        {
            var sqliteConnection = new SqliteConnection();
 
            try
            {
                string connectionString = $"Data Source={fileName}";
                SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
                sqliteConnection = new SqliteConnection(connectionString);
            }
            catch
            {
                sqliteConnection = null;
            }
 
            return sqliteConnection;
        }
Qu'est-ce qui pour vous est le mieux ? Le plus propre, plus académique ... etc