+ 2

Types of methods in C#

Guys please help on types of methods

29th Jun 2020, 10:56 AM
$ayimaster
7 odpowiedzi
+ 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; ... } }
29th Jun 2020, 4:37 PM
David Carroll
David Carroll - avatar
+ 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; }
29th Jun 2020, 7:09 PM
David Carroll
David Carroll - avatar
+ 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
29th Jun 2020, 11:05 AM
$ayimaster
+ 1
Please elaborate more. Can you show us the different syntaxis ? In C# every method has a return type.
29th Jun 2020, 4:16 PM
sneeze
sneeze - avatar
+ 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 ....
29th Jun 2020, 4:58 PM
$ayimaster