Disappearing game object script error

I am very new to C# and only really know javascript html and a bit of C++ and I am having an error which I am sure is very obvious with a script I am making the error seems simple and I sure it is but i have tried figurin out where I did properly do what the errors says however I also may jsut be being stupid bc I do not really now C# sharp here is the error:
Assets\sprites\Scripts\Dog.cs(18,5): error CS8803: Top-level statements must precede namespace and type declarations.
Here is the script it is like 5 lines very simple:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Dog : MonoBehaviour
{
    void OnTriggerEnter2D(Collider2D collider)   // Start is called before the first frame update
    {
        if (collider.gameObject.CompareTag("Player"))
        {

        }

        {

        }
    }   }
    Destroy(gameObject);

write it like this

using System.Collections.Generic;
using UnityEngine;

public class Dog : MonoBehaviour
{
    void OnTriggerEnter2D(Collider2D collider)   // Start is called before the first frame update
    {
        if (collider.gameObject.CompareTag("Player"))
        {
            Destroy(gameObject);
        }
    }   
    
}

It did not work but thank you anyway