0

Why does Print Method couldn't be invoked ?

I set class as static and I've tried to instance an object of this method, but it didn't work. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn {class Program { static void Main(string[] args) { string text = Console.ReadLine(); int intNum = Convert.ToInt32(Console.ReadLine()); double doubNum = Convert.ToDouble(Console.ReadLine()); Printer.Print(text); Printer.Print(intNum); Printer.Print(doubNum); } } static class Printer { static void Print<T>(T text) { Console.WriteLine("Showing ",text); } //your code goes here } }

19th Feb 2021, 12:26 AM
Yasswecancn
Yasswecancn - avatar
4 Answers
+ 5
`static` makes `Print` method a class method, that is a method directly callable from the `Printer` class without a need for instantiating an instance. `public` makes the `Print` method be accessible from outside the `Printer` class.
19th Feb 2021, 3:23 AM
Ipang
+ 4
Make it public static void.. public makes it accessible
19th Feb 2021, 1:18 AM
LordHill
LordHill - avatar
0
Great answer,it works,but why do I need an additional public?
19th Feb 2021, 2:08 AM
Yasswecancn
Yasswecancn - avatar
0
Isn't that static already make it accessible?
19th Feb 2021, 2:09 AM
Yasswecancn
Yasswecancn - avatar