Code analysis can be very useful including telling you which variables, parameters etc. are not being used.
Sometimes however you can not just remove the parameter in the case where the function has to meet an existing signature.
C# 7.0 allows you to name the parameters _
(the underscore symbol) to indicate that you are intentionally not using the parameter and will not reference it.
Code
C#
class PdfDocWriter : IDocWriter
{
void WriteDocument(Document doc, PrintSettings _)
{
var filename = Path.Combine(doc.Filename, ".pdf");
File.WriteAllBytes(filename, pdfService.Render(doc));
}
}
C#
class PdfDocWriter : IDocWriter
{
void WriteDocument(Document doc, PrintSettings printSettings)
{
var filename = Path.Combine(doc.Filename, ".pdf");
File.WriteAllBytes(filename, pdfService.Render(doc));
}
}
Notes
- Can be used with
out
parameters to throw away the result - Extended to lambdas and anonymous methods with Lambda discard parameters C# 9.0