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

Roll up your sleeves and get knee deep into coding!
Practise, make mistakes, learn to search for solutions,seek help when stuck badly! Just attending classes won't make you good at coding!!!

Inversion of Control
Problem You have classes that have dependencies on services or components whose concrete type is specified at design time. In this example, ClassA has dependencies on ServiceA and ServiceB. Figure 1 illustrates...

Trends in .Net Platform
.NET Framework is a software framework developed by Microsoft. It includes a large class library named Framework Class Library (FCL) and provides language interoperability (each language can use code written...

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...

C#.Net Interview Question and Answers
1. What is C#? C# (pronounced "C sharp") is a simple, modern, object-oriented, and type-safe programming language. It will immediately be familiar to C and C++ programmers. C#...
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