JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
A class is never instantiated, or never used.
Classes that are defined in a project but never used are possibly legacy code, that could be removed or left in the version control system only. This would clean the project and avoid spurious code. Moreover, in some cases an unused class might be the sign of a bug, if the programmer expected it to be used.
Methods or constructors never used in the code are often harmless, except for an increase in size of the application. In some cases, however, unused methods are the sign of a stale application interface that needs cleaning or of the necessity to introduce an abstract method.
| Class Name | Unused Class (C#) | |||
|---|---|---|---|---|
| Significance | reliability | |||
| Mnemonic | CSHARP.STRUCT.UUCLASS | |||
| Categories |
|
|||
| Availability | Available for C# only. |
|||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Unused Class (C#)" |
using System;
namespace DocumentationExamples {
public class UnusedClass {
interface ITask {
void Go();
}
abstract class SubTask : ITask { // "Unused Class (C#)" warning issued here
// - this class is never used in the code and could be removed
private static int goCounter;
void ITask.Go(){
goCounter++;
GoImpl();
}
protected abstract void GoImpl();
protected static int HowManyRuns(){
return goCounter;
}
}
class Tmp : ITask {
void ITask.Go(){
Console.WriteLine("I'm running");
}
};
public static void Main(string[] args){
new Tmp();
}
}
}
For a concrete class, remove the class from the program and simplify the code. If you expected the class to be used, determine why it is not.
For an interface or abstract class, check to see if can be simplified, or if an abstract method could replace a non-abstract method.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.