C# Programming - Functions and Subroutines - Discussion
Discussion Forum : Functions and Subroutines - General Questions (Q.No. 9)
9.
If a procedure fun() is to receive an int, a Single & a double and it is to return a decimal then which of the following is the correct way of defining this procedure?
Discussion:
6 comments Page 1 of 1.
Anindita said:
8 years ago
Let's assume the procedure as method or function, so I tried with this following code, and it is working fine:
namespace Testreturntype
{
class Program
{
static void Main(string[] args)
{
Console.Write(fun(5, 2, 2.00));
Console.ReadKey();
}
public static decimal fun(int a, Single s, double k)
{
decimal d = Convert.ToDecimal(a * s * k);
return d;
}
}
}
namespace Testreturntype
{
class Program
{
static void Main(string[] args)
{
Console.Write(fun(5, 2, 2.00));
Console.ReadKey();
}
public static decimal fun(int a, Single s, double k)
{
decimal d = Convert.ToDecimal(a * s * k);
return d;
}
}
}
Alek said:
1 decade ago
There is no such thing as procedure in C#.
Raghvendra Singh said:
1 decade ago
"out" parameter is used to return single or multiple values in case of declaring a function as void (no return type).
Fred said:
1 decade ago
What about :
void fun (int i, Single j, double k, out decimal m) ?
void fun (int i, Single j, double k, out decimal m) ?
Tipu said:
1 decade ago
Why not C# methods return a value?
Andrew Cope said:
1 decade ago
Bad question. C# programmers shouldn't use the term 'procedure'. They are functions or methods.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers