Ryan McBeth
Ryan McBeth
@RyanMcBethProgramming·1.1M subscribers·1.8K videos

Passing by value and reference - C# Gotcha! Interview Questions.

Posted

April 11, 2021

Views

2,232

Likes

181

Comments

25

Engagement

9.23%

Search the Record

Indexed

Every word spoken in this episode is indexed. Type any phrase to jump straight to the moment it was said.

Type any word or phrase that may have been spoken. Click a result to seek the player to that exact moment.

Try a name, a topic, or a quoted line

YouTube Description

as posted by the channel

Pass by value and pass by reference are important concepts to understand in C#.

The default method of passing a parameter in C# is by value, which creates of copy of the type that you pass. However, the kind of copy performed differs if your type is a value type (int / struct) or a reference type ( object / string). Value types have their entire value copied on the stack. Reference types have the reference to their memory location copied - so the reference type essentially has two references to it while in the scope of your method.

Passing by reference differs from passing by value because .NET passes a reference to the original memory location of the variable. This can have some unintended consequences if you aren't careful.

The parameter keywords IN and OUT also play a role in passing by reference. IN passes by reference as read only, while OUT passes by reference and requires that you add a value to the parameter before you return.

The Code for this is available below:

ryanmcbeth.com

Guests & Subjects Covered

C# Gotcha! Interview Questions.C TheThe Code

Sentinel Indexing in Progress

Metadata and chapters are available. Claim extraction for this episode is pending.

All video content is delivered via YouTube embedded players in accordance with the YouTube Terms of Service. Sentinel provides research tools that promote discovery and accountability across political media.