×

C# Function call by value

When you call the function by value, the copy of the actual value is passed in the function instead of its reference. The following example includes the function call by value.
using System;                                                        
public class Program
{
            public int square (int m)
            {
                        return m*m;
            }
            public static void Main(string[] args)
            {
                        int num=Convert.ToInt32(Console.ReadLine());
                        Program p1=new Program();
                        int m=p1.square(num);
                        Console.WriteLine(m);                    
            }
}
Output
10
10 X 10 is 100

Related Topics

C# Access Modifiers

C# provides various keywords to control or restrict accessibility or scope of the data. We can apply access modifiers to functions and variables. There are five access modifiers in C#: Private ...

10 minutes read.

C# Data Types

A Data type is the type of data which the variable can store such as integer, float, double, character, etc. In C#, Data types are divided into three parts 1. Value data type 2....

2 minutes read.

C# Constructors

In C#, Constructor is the special method with no return type. It is invoked automatically at the time of object creation. Its name must be the same as the class...

2 minutes read.

C# Variables

A variable is a symbol used to store user’s data. It represents a memory location. Its value can be changed multiple times and can be reused many times.Example: int a; //integer...

1 minute read.

C# Command Line Arguments

In C#, Arguments to the main method can be sent by command line. Those arguments are called command line arguments. The string[] args variable holds the command line arguments Let's see...

1 minute read.

C# Function

A function represents a block of code that has its specific signature. Operating functions includes three operations: Function declaration Function definition Function calling Declaring function is defining the signature of the...

4 minutes read.

C# Keywords

Keywords are the reserved words with special meaning. They can’t be used as variables and Identifiers. If you want to use them as identifiers, you must use ‘@’ character prior...

1 minute read.

C# Abstraction

Abstraction is a mechanism by which we can hide the complexities and show only functionalities. C# provides an abstract keyword to declare a class and method as abstract. In C#,...

2 minutes read.

C# First Application

Let's see the first simple program in C# which prints Hello word on the console. class FirstExample { static void Main (string[] args) { System.Console.WriteLine("Hello World "); } } Output Hello World Description of the first Program: class: it’s...

2 minutes read.

C# Member overloading

If we define two members in a class with the same name then it's called member overloading. Advantage of member overloading is the thing that we don't need to give...

4 minutes read.

C# Structs

In C#, Structs are like classes but they are used to create light weight objects like color, Rectangle, etc. Structs are value type unlike classes that are reference type. Using...

3 minutes read.

Boxing and Unboxing in C#

The boxing and unboxing are the terms that refers to the data types in the c# language. The c# language is the frontend language for developing applications. We know that the...

3 minutes read.

C# Params

There are cases when we don’t know the actual number of parameters in the function call. Well, in C# we can pass any number of parameters in the function call...

3 minutes read.

C# If Statements

In C#, If Statements are used to check the condition. Expression given in if statement is evaluated, If it is true then if block gets executed if it is false...

2 minutes read.

C# Properties

In C#, Properties enables class to provide a public way of setting and getting values or fields of the class. Properties provides Encapsulation in the class if we make all...

2 minutes read.

C# Aggregation

In C#, Aggregation Represents Has-A Relationship between two objects. A field of the class defines another class to reuse this in the form of association. The class is used as...

3 minutes read.

C# Call by reference

In C#, we can use ref keyword to pass the reference to the original value instead of the copy of the original value. the changes that are made in the...

2 minutes read.

C# Jagged Arrays

C# provides the concept of jagged array which means array of arrays. The elements of jagged array are also arrays. The element size of jagged array can vary.C# Jagged Arrays...

3 minutes read.

C# Jump Statements

Break is a jump statement which is used to break the current loop or current flow of program and transfer the program control to the next block. It is used...

3 minutes read.

C# static class

In C#, static class is the one which can only contain static members. It can’t be instantiated. It cannot be inherited. It can only have static constructors and cannot contain...

3 minutes read.