+ 2
Types of methods in C#
Guys please help on types of methods
7 Respostas
+ 7
$ayimaster It sounds like you are used to seeing something like this:
public bool Execute() {
...
return isExecuted;
}
Are you confused about methods like the following which has no return value:
public void Execute() {
...
}
Or... Are you possibly referring to a class constructor that might look like a method with no return type or void keyword:
class SendHandler {
public SendHandler() {
//Initialize this class instance
...
}
public SendHandler(ISender sender) {
//Initialize this class instance
//with this parameter argument.
Sender = sender;
...
}
}
+ 4
Another thing you might be confused about is C# property setter and getter syntax, which could also look somewhat like methods.
public class SendHandler {
private ISender _sender;
public ISender Sender {
get {return _sender; }
set {_sender = value;}
}
}
These are essentially property getters and setters which essentially compile to methods in CIL... similar to something like the following:
ISender get_Sender() {
return _sender;
}
void set_Sender(ISender sender) {
_sender = sender;
}
+ 2
Alexander Thiem ... I learnt on solo learn about methods but l noticed they have different syntax as l progressed .... They nolonger start wth a return type only. Please help
+ 1
Please elaborate more. Can you show us the different syntaxis ?
In C# every method has a return type.
+ 1
David
Carroll you got me right l refer to all of the above please show us the examples of the methods in their different syntax
And how to call them ....