What is Functions in VB.Net

इस पोस्ट में हम डॉट नेट के फंक्शन के बारे में जानेगे |

Functions

Functions subroutine के तरह ही code के blocks है जो की calling program को value return करते है। subroutines किसी define किए गए task को पूरा करने के बाद कोई भी value return नहीं करते है जबकि Functions किसी define किए गए task को पूरा करने के बाद calling program को एक value return करते है। Function subroutine की तरह ही arguments accept करते है। Functions को declare करने के लिए Function………………… End function statement का प्रयोग किया जाता है।

Syntax:
<Access modifier> Function <Function Name> ([arguments]) As <Return Type>
[Function’s statements] Return <returning value>
End Function

Example:
Private Function Sum ( ) As Double
Dim a, b, c as Double
a = Val (Textbox1.Text)
b = Val (Textbox2.Text)
c= a + b
Return (c)
End Function

Access modifier function के scope को बताता है। यह private, public और friend हो सकता है।

Return Type

VB.Net मे सभी functions value return करते है इसलिए सभी functions का type होता है जिसे की return type कहते है और return होने वाली value को return value कहते है। function का return type, returning value और calling code मे use होने वाला variable का type हमेशा एक ही होना चाहिए। return type किसी भी टाइप का हो सकता है जैसे class, datatype, structure, object etc.

Returning Value

Function से return की जाने वाली value को returning value कहते है। returning value function के return type पर depend करती है। value को return करने के लिए Return keyword का use किया जाता है।


Syntax: Return (returning value)
Example: Return (c)


error: Content is protected !!