C# (Sharp) Programming Language Question:
Difference between a sub and a function in C#.
Answer:
Answer1
A Sub does not return anything whereas a Function returns something.
Answer2
-A Sub Procedure is a method will not return a value
-A sub procedure will be defined with a “Sub” keyword
Sub ShowName(ByVal myName As String)
Console.WriteLine(”My name is: ” & myName)
End Sub
-A function is a method that will return value(s).
-A function will be defined with a “Function” keyword
Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim sum As Integer = num1 + num2
Return sum
End Function
A Sub does not return anything whereas a Function returns something.
Answer2
-A Sub Procedure is a method will not return a value
-A sub procedure will be defined with a “Sub” keyword
Sub ShowName(ByVal myName As String)
Console.WriteLine(”My name is: ” & myName)
End Sub
-A function is a method that will return value(s).
-A function will be defined with a “Function” keyword
Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim sum As Integer = num1 + num2
Return sum
End Function
Previous Question | Next Question |
directcast(123.34,integer) - should it throw an error? Why or why not? | Explain manifest & metadata in C#. |