BasicKnowledgeCSharp/LessonsAndTasks/Lesson 44 - Ключевое слово out, разница out и ref/Program.cs
Dvurechensky 058c8f2679 1.0
Main
2024-10-05 09:59:53 +03:00

38 lines
906 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Text;
/*
* Ключевое слово out
* Разница между ref и out
*/
class Program
{
public static void Foo(ref int value)
{
value++;
System.Console.WriteLine(value);
}
/// <summary>
/// Change input val
/// out - обязывает нас присваивать значение переменной внутри метода
/// </summary>
/// <param name="value">value</param>
public static void Bar(out int value)
{
value = 0;
System.Console.WriteLine(value);
}
static void Main()
{
int a = 10;
int aa;
Foo(ref a);
Bar(out aa);
string str = "3";
int.TryParse(str, out int result);
Bar(out int aaa); // сразу можем объявить внутри метода с out
Console.ReadKey();
}
}