-3

I have code

PrinterSettings set = new PrinterSettings();
set.PrinterName = set.InstalledPrinters[0];

I can’t compile it because of error (Google translate): it is not possible to access this via an instance link.

How to fix it?

Okumaima
  • 53
  • 1
  • 8
  • If you have an error message, usually this have also an error number. The best thing to do is to start your browser and search for that error code. – Steve Jan 30 '21 at 15:27
  • Here the result for CS0176: https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0176 – Steve Jan 30 '21 at 15:29

1 Answers1

2

InstalledPrinters is a static property, so use the class name and not the instance name to access it:

set.PrinterName = PrinterSettings.InstalledPrinters[0];

Note that this will crash if there are no printers installed, so better check if PrinterSettings.InstalledPrinters is not empty.

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36