![victorialeona81](/avatars/20165.jpg)
victorialeona81
13.07.2019 •
Computers and Technology
Reference variables allow arguments to be passed by
Solved
Show answers
More tips
- H Health and Medicine How to Improve Eyesight: Science-based Techniques to Enhance Your Visual Acuity...
- F Family and Home Do Lullabies Help Babies Sleep or Is it Just a Myth?...
- H Health and Medicine Tick Traps: How to Remove Them Safely and Effectively...
- S Society and Politics Why are thugs called gopniks ? A fascinating journey through Russian subculture...
- A Animals and plants Want a Perfect Lawn? Learn How to Plant Grass the Right Way...
- A Animals and plants How to Properly Care for a Pet Decorative Rabbit at Home?...
- C Computers and Internet How to Check the Speed of My Internet?...
- H Health and Medicine 10 Ways to Cleanse Your Colon and Improve Your Health...
- W Work and Career How to Write a Resume That Catches the Employer s Attention?...
- C Computers and Internet Е-head: How it Simplifies Life for Users?...
Answers on questions: Computers and Technology
- C Computers and Technology A shopkeeper offers 10% discount on the price, a customer has to pay 6% sales tax on the remaining amount to be paid by the customer taking the price as input in python...
- W World Languages Which language is not one of the official united nations languages? french german chinese english...
- M Mathematics a wall in marcus s bedroom is 825825 feet high and 18131813 feet long. if he paints 1212 of the wall blue, how many square feet will be blue?...
- H History Spain was held by the muslims for less than 50 years. true or false...
- P Physics Two golf balls are hit from the same point on a flat field. both are hit at an angle of 30∘ above the horizontal. ball 2 has twice the initial speed of ball 1. if ball...
- C Chemistry Asolution is made by dissolving 3.40 g of nacl in water to form 58.75 g of solution. what is the mass percent solute in the solution?...
- S Social Studies Quick ! how do people organize the world into human regions?...
- B Business Many companies are hesitant to hire or re-hire workers full time because: employee morale declines when former workers are re-hired.it makes promotion and placement decisions...
- A Arts What is the best tool for calligraphy when you dont have the ink?...
- M Mathematics Iknow the answer is (-1,4) but i still don t understand it...
Ответ:
Reference
Explanation:
The Reference type variable is such type of variable in C# that holds the reference of memory address instead of value. Examples for reference type are classes, interfaces, delegates and arrays.
We can pass parameters to the method by reference using ref keyword
It’s mandatory to initialize the variable value before we pass it as an argument to the method in c#
For example,
int x = 10; // Variable need to be initialized
Add(ref x); // method call
If you pass parameters by reference in method definition, any changes made to it affect the other variable in method call.
Here's a sample program:
using System;
namespace ConsoleApplication
{
public class Test
{
public static void Main()
{
int i = 10;
Console.WriteLine("i=" + i);
Add(ref i);
Console.WriteLine("i=" + i);
Console.ReadLine();
}
public static void Add( ref int j)
{
j = j + 10;
Console.WriteLine("j="+j);
}
}
}
Output:
i=10
j=20
i=20
Ответ: