Last active
August 6, 2020 16:38
-
-
Save conficient/ee7b7249c43b07bc19365813b44ad2df to your computer and use it in GitHub Desktop.
IEnumerable does not protect your list..
This file contains 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 Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System; | |
using System.Collections.Generic; | |
namespace Tests | |
{ | |
[TestClass] | |
public class Test | |
{ | |
[TestMethod] | |
public void MyTestMethod() | |
{ | |
var x = new ListTest(); | |
var l = (List<string>)x.List; | |
l.Add("test"); | |
foreach (var item in x.List) | |
{ | |
Console.WriteLine(item); | |
} | |
} | |
} | |
public class ListTest { | |
public IEnumerable<string> List => _list; | |
private List<string> _list = new List<string>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment