C# Programming - Functions and Subroutines
Why should I learn to solve C# Programming questions and answers section on "Functions and Subroutines"?
Learn and practise solving C# Programming questions and answers section on "Functions and Subroutines" to enhance your skills so that you can clear interviews, competitive examinations, and various entrance tests (CAT, GATE, GRE, MAT, bank exams, railway exams, etc.) with full confidence.
Where can I get the C# Programming questions and answers section on "Functions and Subroutines"?
IndiaBIX provides you with numerous C# Programming questions and answers based on "Functions and Subroutines" along with fully solved examples and detailed explanations that will be easy to understand.
Where can I get the C# Programming section on "Functions and Subroutines" MCQ-type interview questions and answers (objective type, multiple choice)?
Here you can find multiple-choice C# Programming questions and answers based on "Functions and Subroutines" for your placement interviews and competitive exams. Objective-type and true-or-false-type questions are given too.
How do I download the C# Programming questions and answers section on "Functions and Subroutines" in PDF format?
You can download the C# Programming quiz questions and answers section on "Functions and Subroutines" as PDF files or eBooks.
How do I solve C# Programming quiz problems based on "Functions and Subroutines"?
You can easily solve C# Programming quiz problems based on "Functions and Subroutines" by practising the given exercises, including shortcuts and tricks.
- Functions and Subroutines - General Questions
namespace IndiabixConsoleApplication
{
class SampleProgram
{
static void Main(string[] args)
{
int num = 1;
funcv(num);
Console.Write(num + ", ");
funcr(ref num);
Console.Write(num + ", ");
}
static void funcv(int num)
{
num = num + 10; Console.Write(num + ", ");
}
static void funcr (ref int num)
{
num = num + 10; Console.Write(num + ", ");
}
}
}
namespace IndiabixConsoleApplication
{
class SampleProgram
{
static void Main(string[] args)
{
int[]arr = newint[]{ 1, 2, 3, 4, 5 };
fun(ref arr);
}
static void fun(ref int[] a)
{
for (int i = 0; i < a.Length; i++)
{
a[i] = a[i] * 5;
Console.Write(a[ i ] + " ");
}
}
}
}
- An argument passed to a ref parameter need not be initialized first.
- Variables passed as out arguments need to be initialized prior to being passed.
- Argument that uses params keyword must be the last argument of variable argument list of a method.
- Pass by reference eliminates the overhead of copying large data items.
- To use a ref parameter only the calling method must explicitly use the ref keyword.
- A function cannot be called from a subroutine.
- The ref keyword causes arguments to be passed by reference.
- While using ref keyword any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method.
- A subroutine cannot be called from a function.
- Functions and subroutines can be called recursively.