0

why output : Method must have a return type ?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { class abc { private int age; private string name ; public Pname(string nm) { name = nm; } public string getname() { return name; } } static void Main (string[] args) { abc ab = new abc("asfat"); Console.WriteLine(ab.getname()); } } }

3rd Jan 2017, 2:35 PM
baiyu
baiyu - avatar
1 Answer
0
Actualy, the problem has nothing to do with the return type. The main problem is at your Constructor: public Pname(string nm) { name = nm; } Constructors must have the same name as their Class so that must be: public abc(string nm) { name = nm; } and that will fix it.
3rd Jan 2017, 6:46 PM
Erwin Mesias
Erwin Mesias - avatar