3
button1.Click += new System.EventHandler(button1_Click);

For this code above the VS gives warning of CS8622 for "button1_Click" in the EventHandler: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings?f1url=%3FappId%3Droslyn%26k%3Dk(CS8622)

In the VS it says: "Nullability of reference types in type of parameter 'sender' of 'void Form1.Button2_Click(object sender, EventArgs e) doesn't match the target delegate 'EventHandler' (possibly because nullability attributes)".

namespace BirUygulama
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            Button button1 = new Button();
            Font fon = new Font("Corbel", 18, FontStyle.Italic);
            button1.Font = fon;
            Point buttonLoc = new Point();
            buttonLoc.X = 520;
            buttonLoc.Y = 444;
            button1.Location = buttonLoc;
            button1.Size = new Size(100, 85);
            button1.ForeColor = SystemColors.MenuHighlight;
            button1.BackColor = Color.Azure;
            this.Controls.Add(button1);
            button1.Text = "Giriş";
            button1.Click += new System.EventHandler(button1_Click);
        }
    }
}

What does this warning mean and how do I solve this warning? enter image description here

  • 1
    `private void Form1_Load(object? sender, EventArgs e) { }` -- It's just a warning, hints to check `sender` for null – Jimi Sep 23 '22 at 09:43
  • @Jimi but I do not understand what it is telling me to do and the reason why it is telling me so. – Programmable Physics Sep 23 '22 at 09:45
  • Did you check what's in the code snippet in my previous comment? You have `nullable` enabled, `sender` is defined as `object?`, not `object` – Jimi Sep 23 '22 at 09:46
  • @Jimi I really still do not get it... It says "sender", yes? It's okay, dont know what do you mean. – Programmable Physics Sep 23 '22 at 09:52
  • [Nullable reference types (C# reference)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-reference-types) – Jimi Sep 23 '22 at 09:54

0 Answers0