❔ can I make variable nullable withouse initializing it?

I have this method that connect to database and I am checking if it connected:
        //Method connects to database
        public MySqlConnection ConnectDatabase()
        {
            MySqlConnection? connection;
            string config =
                "server = 127.0.0.1;" +
                "user = root;" +
                "database = trivia_bot_data";
            try
            {
                connection = new MySqlConnection(config);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                connection = null;
            }
            return connection;
        }
Was this page helpful?