Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ValueTypeVsReferenceType
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- ReferenceType akarmi = new ReferenceType();
- int number = 10;
- PrintNumber(akarmi.asd);
- ArrayExample array = new ArrayExample();
- array.Initialize();
- BoxingExample boxingExample = new BoxingExample();
- object boxedNumber = boxingExample.BoxNumber(42);
- }
- private static void PrintNumber(ReferenceType referenceType)
- {
- Console.WriteLine(referenceType);
- referenceType.asd = 30;
- }
- public static void PrintNumber(int asd)
- {
- Console.WriteLine(asd);
- asd = 30;
- }
- }
- public class ReferenceType
- {
- public static int Vaaaaa;
- public static int Vaaaaa2 = GetLofac();
- private static int GetLofac() => 5 + Vaaaaa;
- public int asd = GetLofac();
- static ReferenceType()
- {
- Vaaaaa = 22;
- }
- public int MyProperty => 10;
- public int MyProperty2
- {
- get
- {
- return 10;
- }
- }
- public ReferenceType()
- {
- MyProperty6 = "555";
- }
- public string MyProperty3 => "valami";
- public readonly string MyProperty5 = "valami";
- public string MyProperty6 { get; } = Calculate();
- private static string Calculate()
- {
- return "valami" + "_20";
- }
- public string MyProperty4
- {
- get
- {
- return "valami";
- }
- }
- }
- public class ArrayExample
- {
- public void Initialize()
- {
- int[] array = new int[10];
- string valami = "empty";
- ChangeString(valami);
- Console.WriteLine(valami);
- }
- public void ChangeString(string str)
- {
- str = "hehehehee";
- MyEnum two = MyEnum.None;
- MyEnum three = MyEnum.Three;
- int first = (int)two;
- int second = (int)three;
- MyEnum flag = MyEnum.One | MyEnum.Two;
- int flagInt = 1 | 2;
- if ((flag & MyEnum.One) == MyEnum.One)
- {
- if ((flag & MyEnum.Two) == MyEnum.Two)
- {
- string valami2 = null;
- string valami3 = valami2 ?? "lel";
- string valami4 = valami2 == null ? "lel" : valami2;
- Nullable<bool> valami = new Nullable<bool>();
- if (valami.HasValue)
- {
- Console.WriteLine(valami.Value);
- }
- }
- }
- }
- }
- public class BoxingExample
- {
- public object BoxNumber(int number)
- {
- return number;
- }
- }
- public enum MyEnum
- {
- None = 8,
- One = 1,
- Two = 2,
- Three = 8,
- }
- class Example
- {
- static int x = 1;
- int y = 2;
- static Example() { Console.WriteLine("Static constructor"); }
- public Example() { Console.WriteLine("Instance constructor"); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement