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

.NET With AngularJS Training Program Syllabus
What You will Learn in .NET with AngularJS Training Program? Introduction to .Net: Features of .Net, CTS, CLS, CLR and MSIL. C# & .Net Basics and Branching & Flow Control. OOPs Concepts,...

Technology learning Tip
To learn any technology especially related programming you need to think logically and need good practice time. Never try to start from scratch or start reading a book related to to learn a subject. ...

Service-Level Agreement (SLA) Definition
A service-level agreement (SLA) is a contract between a service provider and its internal or external customers that documents what services the provider will furnish. SLAs originated with network service...
M

Mohammad Shafi

0 0
0

Coding Instructions To Prevent SQL-Injection
SQL-Injection is a very sensitive and very common technology to hack an application. I am describing a few techniques to make the SQL-Injection difficult. The main point of injection is a dynamic query....

Read CSV data using ODBC Connection
Codes to read the CSV data using ODBC Connection- Input File: File's Encoding format should be ANSI as below class Student{ public string CollegeId { get; set; } public string AdmissionDate...
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