What do you know about methods in C#?
Answer
Methods contain code that does something. They are like boxes that encapsulate its content.
Each method consists of method signature and method body.
The method signature is composed of method name, method parameters, method return data type and access modifier.
The method body contains code.
You can run the code that is in the method body by calling the method.
The first part of the method signature is an access modifier. It defines whether the method is visible to the external code and whether it can be called. Two basic access modifiers are public and private.
The second part of the method signature is method return data type. It defines what type of result will be returned by the method after it is called. It can be number, string, bool or any other data type.
The third part of the method signature is method name. Method name should be short and it should describe what the method does. Giving a method a good name that the others will understand is one of the important skills of good programmers.
A method can be either instance method or static method.
The instance method cannot be called without having an instance of class created. You have to first create an object and then you can call the instance method using the object.
The static method doesn't need an instance of class created. You can call the method directly on a class. Such method however cannot access values from the object (because the object was never created).
In the following example, we can see:
- the access modifier is 'public' which means the method is visible to all code.
- the return data type is 'int', which means the integer number will be returned by the method as a result of its execution.
- the name of the method is Calculate
The method has:
Related C# job interview questions
What is an attribute in C#?
C# JuniorWhat must every method have in C#?
C# JuniorWhat is execution context in C#?
C# JuniorWhat is a local variable and where can it be declared in C#?
C# JuniorWhat is a global variable and where can it be declared in C#?
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