How do you recognize a method call in C#?
Answer
In C# there are several ways how to call a method. Both ways have one thing in common. You can always see a name of the methd and opening and closing rounded brackets following the name.
If there is a dot or space before the method name and there isn't a data type before it, it is a method call.
Let's have a look at couple of examples.
The first way how you can call a method is to call one method from another method where both methods are defined within the same class.
In the example below, if someone calls the method TurnOn(), the method TurnOff() will automatically be called by the method TurnOn().
So whenever someone turns the radio on, it will automatically turn itself off. Yeah, it's a bit useless radio this way, right? But at least it does something.
The second way is when you call one method from another method where each method is defined within a different class and the called method is called on an instance of a class.
In the example below, when the Program is executed and the method Main is called, the new radio object is created and then the metod TurnOn()
is called on this newly created object.
The third way way how to call a method is to call one method from another method where each method is defined within a different class and the called method is called directly on a class without an instance of an object to be created.
Such method must be marked by the keyword 'static'.
In the example below, not that when we are calling the method PrintHello(), there is no instance of class Printer created.
We are calling the method directly on a class Printer.
Related C# job interview questions
What C# data types do you know?
C# JuniorWhat is a data type?
C# JuniorWhat is a method in C# and how do you define one?
C# JuniorWhat is a constructor in C# and why would you use it?
C# JuniorWhat parts does a C# class usually contain?
C# Junior
Chat
Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.
e
@@xeDO0
1'"
e'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
L7oVYP7m')) OR 312=(SELECT 312 FROM PG_SLEEP(15))--
A1v25QPv') OR 393=(SELECT 393 FROM PG_SLEEP(15))--
kxT46vOm' OR 479=(SELECT 479 FROM PG_SLEEP(15))--
VTgcz37T'; waitfor delay '0:0:15' --
1 waitfor delay '0:0:15' --
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
if(now()=sysdate(),sleep(15),0)
-1" OR 3+906-906-1=0+0+0+1 --
-1" OR 2+906-906-1=0+0+0+1 --
-1' OR 3+316-316-1=0+0+0+1 or '8BoDIAd6'='
-1' OR 2+316-316-1=0+0+0+1 or '8BoDIAd6'='
-1' OR 3+137-137-1=0+0+0+1 --
-1' OR 2+137-137-1=0+0+0+1 --
-1 OR 3+877-877-1=0+0+0+1
-1 OR 2+877-877-1=0+0+0+1
-1 OR 3+418-418-1=0+0+0+1 --
-1 OR 2+418-418-1=0+0+0+1 --
e
e