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

Programming Practice Technique
Any Programming Language required an Algorithm. Algorithm - It is the finite set of instructions in which each and every instruction has the meaning, instructions are not ambiguous and all the instructions...

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

Format Date to “MM/dd/yyyy” in Webgrid ASP.Net MVC Razor View
Replace above line with below to apply ("DD/mm/yyyy") formatting to date field in WebGrid AllTicket.Column(columnName: "DueDate", header: "Due Date") grid.Column("Date",format:@<text> @item.Date.ToString("MM/dd/yyyy")</text>)
M

Mohammad Shafi

0 0
0

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