diff --git a/gradebook/test/GradeBook.Tests/TypeTests.cs b/gradebook/test/GradeBook.Tests/TypeTests.cs index be2fd45..7b63549 100644 --- a/gradebook/test/GradeBook.Tests/TypeTests.cs +++ b/gradebook/test/GradeBook.Tests/TypeTests.cs @@ -6,6 +6,40 @@ namespace GradeBook.Tests using GradeBook; public class TypeTests { + [Fact] + public void ValueTypesAlsoPassByValue() + { + var x = GetInt(); + Assert.Equal(3,x); + + SetInt(ref x); + Assert.Equal(42, x); + } + + private void SetInt(ref int x) + { + x = 42; + } + + private int GetInt() + { + return 3; + } + + [Fact] + public void StringsBehaveLikeValueTypes() + { + string name = "Jason"; + MakeUppserCase(name); // try to change String like a reference + + Assert.Equal("Jason", name); // ToUpper does not work on String, although it's reference. It's copied as value + } + + private void MakeUppserCase(string arg) + { + arg.ToUpper(); + } + [Fact] public void CSharpCanPassByReference() {