Towhid
Towhid

Reputation: 2084

Return type of property in C# .net

If there is only a set part in a Property, then is there any need to declare a return type? For example:

public string Email
{
   set { email = value; }
}

In the above example is there any need of the word "string" after public?

Upvotes: 0

Views: 436

Answers (3)

Claudio Redi
Claudio Redi

Reputation: 68400

The simple answer is: It's not possible to have a property without a type

Think that value is of the type that you specified so it's not that it's not being used.

Upvotes: 1

Rowland Shaw
Rowland Shaw

Reputation: 38130

Yes. The compiler needs to know so that it can check the type when you try to set the property.

Upvotes: 4

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68687

Otherwise you wouldn't know the type of value.

Upvotes: 3

Related Questions