Μέχρι τώρα πίστευα ότι να δηλώσει ένα struct & έναν constructor με το ίδιο όνομα είναι απλό:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LessonConsoleApplication2
{
class Program
{
struct Person
{
public string firstName;
public string lastName;
public int age;
}
public Person(string _firstName, string _lastName, int _age)
{
firstName = _firstName;
lastName = _lastName;
age = _age;
}
public override string ToString()
{
return firstName + " " + lastName + ", age " + age;
}
static void Main(string[] args)
{
Person p = new Person("Tony", "Allen", 32);
Console.WriteLine(p);
Console.Read();
}
}
}
Γιατί όμως επιμένει ο Compiler ότι:
Error 1 Method must have a return type
Γιατί πιστεύει ότι ο Person(string _firstName κτλ) είναι Method;