Last active
July 19, 2019 08:29
-
-
Save yehorhromadskyi/7f16e7e87c7799ba2089101fddaf7066 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
namespace types | |
{ | |
public class ValRefTypes | |
{ | |
public ValRefTypes() | |
{ | |
var i = 10; | |
Console.WriteLine($"Before increment: {i}"); | |
Increment(i); | |
Console.WriteLine($"After increment: {i}"); | |
var sb = new StringBuilder("How are you"); | |
Console.WriteLine($"Before append: {sb}"); | |
AddQuestionMark(sb); | |
Console.WriteLine($"After append: {sb}"); | |
} | |
public void Increment(int i) | |
{ | |
i++; | |
} | |
public void AddQuestionMark(StringBuilder stringBuilder) | |
{ | |
stringBuilder.Append("?"); | |
} | |
public void AddQuestionMark2(StringBuilder stringBuilder) | |
{ | |
stringBuilder = new StringBuilder("?"); | |
} | |
} | |
} | |
namespace inheritance | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Animal dog = new Dog(); | |
dog.Move(); | |
Animal cat = new Cat(); | |
cat.Move(); | |
} | |
} | |
public abstract class Animal | |
{ | |
public virtual void Move() | |
{ | |
Console.WriteLine("Animal is moving"); | |
} | |
} | |
public sealed class Dog : Animal | |
{ | |
public override void Move() | |
{ | |
Console.WriteLine("Dog is moving"); | |
} | |
} | |
public sealed class Cat : Animal | |
{ | |
public new void Move() | |
{ | |
Console.WriteLine("Cat is moving"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment