Finished Passing Parameters by Reference
parent
48b6f32021
commit
6442df3678
|
@ -6,6 +6,50 @@ namespace GradeBook.Tests
|
|||
using GradeBook;
|
||||
public class TypeTests
|
||||
{
|
||||
[Fact]
|
||||
public void CSharpCanPassByReference()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
GetBookSetName(ref book1, "New Name");
|
||||
|
||||
Assert.Equal(book1.Name, "New Name");
|
||||
}
|
||||
|
||||
private void GetBookSetName(ref Book book, string name)
|
||||
{
|
||||
book = new Book(name);
|
||||
book.Name = name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CSharpIsPassByValue()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
GetBookSetName(book1, "New Name");
|
||||
|
||||
Assert.Equal(book1.Name, "Book1");
|
||||
}
|
||||
|
||||
private void GetBookSetName(Book book, string name)
|
||||
{
|
||||
book = new Book(name);
|
||||
book.Name = name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSetNameFromReference()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
SetName(book1, "New Name");
|
||||
|
||||
Assert.Equal(book1.Name, "New Name");
|
||||
}
|
||||
|
||||
private void SetName(Book book, string name)
|
||||
{
|
||||
book.Name = name;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetBookReturnsDifferentObjects()
|
||||
{
|
||||
|
@ -16,6 +60,7 @@ namespace GradeBook.Tests
|
|||
Assert.Equal("Book2", book2.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TwoVarsCanReferenceSameObject()
|
||||
{
|
||||
var book1 = GetBook("Book1");
|
||||
|
|
Loading…
Reference in New Issue