UrbanPro
true

Learn .Net Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why a function in C# requires "Return type"??

Raga Deepthi G.
25/09/2018 0 0

- Basically , a Method is a piece of code used for the re-usability purpose. 

- Method is of 2 types Function and Procedure

Function is a method which returns a value to the calling place

Function syntax:
 
<return type> <functionname>(<params> [ optional ])
{
      //code
}
 
Function samples : 
 
void Display()
{
     Console.WriteLine("Function which returns nothing");
}
 
note : in the above sample , the Display() returns no value, hence "void" is the return type. "void" means nothing.
 
int Add(int a, int b)
{
      return (a+b);
}
 
note : in the above sample , the Add() is returning the sum of 2 numbers passed to it. Means here it is returning an integer value to the calling place.

 

Procedure is a method which returns nothing to the calling place.

Procedure syntax:

<procedurename>(<params>[optional])

{

    //code

}

Procedure samples:

Display()

{

     Console.WriteLine("Procedure returns no value");

}

Add(int a, int b)

{

     Console.WriteLine("Sum : "+(a+b));

}

Hence, a function always returns a value or void to the calling place and a procedure returns nothing.

C# do not support Procedure. So functions in C# should be defined with the return type.

 

 

 

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Multi-core CPU utilization using Task Parallel Library in c#
Nowadays, we are using multiple core systems. We must write our .NET applications in such a way that we must utilise the complete computing power of the machine. The parallel task library(TPL) allows...

Understanding Delegate in C# .NET
C# Delegate technique Delegate is one of the fantastic tool & technique in C#.NET. Using deleagte technique the following benefits could be avaialed One can define a method without name (Anonymous...

The Common Language Runtime
i. It is important to understand that the CLR is an execution environment for .NET applications and that includes applications written in C#, F#, VB.Net and other languages that target the .Net Framework. ...

Multi-core CPU utilization using Task Parallel Library in c#
Nowadays, we are using multiple core systems. We must write our .NET applications in such a way that we must utilise the complete computing power of the machine. The parallel task library(TPL) allows...

.NET FRAMEWORK
.NET FRAMEWORK IS A PLATFORM/AN ENVIRONMENT FOR THE DEVELOPMENT, DEPLOYMENT, AND EXECUTION OF HIGHLY DISTRIBUTED, COMPONENT-BASED APPLICATIONS. Objectives of .NET framework To support platform...
X

Looking for .Net Training Classes?

The best tutors for .Net Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn .Net Training with the Best Tutors

The best Tutors for .Net Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more