While working in a big application where more than one developers are involved, sometimes we may need to change the name or declaration of a particular method – which in turn gives build error or causes the application to crash as it is being used by other developers in the application. In this situation we can use the “Obsolete” attribute to overcome this problem.
For Example :
For getting patient information we are using the method GetPatientInfo(). This method is used by most of the developers for getting Patient Information. So if somebody changes the name or declaration of this method (lets say GetPatientDetails()) , the application may crash or generate build error. So to overcome this problem we can use “Obsolete” attribute of the old method and define a new method (GetPatientDetails()) , also show the proper message to other developers. This change won’t cause any application error. Other developers who are already using GetPatientInfo() will get a compiler warning as “Use GetPatientDetails() for getting Patient Information instead of GetPatientInfo()“.
// [Obsolete("Use GetPatientDetails() for getting PatientInformation instead of GetPatientInfo()")] public string GetPatientInfo() //Old Method { //code for getting Patient Information } public string GetPatientDetails() //New Method { //code for getting Patient Information }