Skip to content

Instantly share code, notes, and snippets.

@conficient
Last active August 6, 2020 16:38
Show Gist options
  • Save conficient/ee7b7249c43b07bc19365813b44ad2df to your computer and use it in GitHub Desktop.
Save conficient/ee7b7249c43b07bc19365813b44ad2df to your computer and use it in GitHub Desktop.
IEnumerable does not protect your list..
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