Hi guys!

I was wondering if there is a way to apply date when marking a method as obsolete? What I mean about a date is that this date represents the "date" when this function should be removed for good.

And a NooB question, is there a way to display error message in winform using MessageBox.show()?

Code:

`

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        [Obsolete("This class is obsolete; use class B instead")]
        class A
        {
            public void F() { }
        }
        class B
        {
            public void F() { }

        }



        private void button1_Click(object sender, EventArgs e)
        {
            A a = new A();       // Warning
            a.F();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            B b = new B();
            b.F();
        }
    }
}

`

Recommended Answers

All 2 Replies

Not that I'm aware of. You should note in the comment and in your documentation that the method is obsolete and will be removed after X date. After that date, simply remove the method from your libraries and documentation.

If you wish to retain true backwards compatibility, then retain the methods, mark them obsolete, but include a reference to the new method that should be used (which you should be doing anyway)

If by Error message you mean an exception then you can put a Try/Catch in you method like this:

private void myMethod()
{
    try
    {
        .....
    }
    catch (Exception ex)
    {
        MessageBox.show("" + ex);
    }
 }

As for the obsolete problem can you not add DateTime.Now.ToString() to the end of the obsolete message?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.