Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
how to declare a constructor in c#?
hello, i have a little problem trying to declare new class in c#
compiler show error indicating i cannot use enclosing type as the same as constructor name
c
4 Answers
- 10 years agoFavorite Answer
It sounds like you are trying to return a value from the constructor. You can't do that.
public int MyClass() <-- wrong
public void MyClass() <-- wrong
public MyClass() <-- right
- Anonymous10 years ago
We can declare the constructors in the class its may be in basic or global.
Source(s): http://www.exposix.com/ - BARON'SLv 410 years ago
public class Employee {
public string FirstName;
public string LastName;
// default constructor
public Employee() {
this.FirstName = "Michelle";
this.LastName = "Laurel";
}
}
Source(s): Experience