Original Post
I am trying to figure out how to pass an element of an array in C# by reference. As a simplified example I am looking to do something like this: However, this gives an error:
static void Main(string[] args)
{
List<int> myList = new List<int>();
myList.Add(1);
Transformation(ref myList[0]);
}
static void Transformation(ref int number)
{
number++;
}
Quote:I am fairly new to using C#, with most of my prior programming experience in C++, but for the most part it seems like C# is fairly loose with letting the coder do what they want, unless there is a safer or cleaner equivalent way of doing the same thing (with minimal change to the code required). So is there any way to do what I am trying to do, or I am just fighting with C# to get it to do something that it was designed not to do? P.S. Why doesn't ++ show up in the preview of my message?
A property or indexer may not be passed as an out or ref parameter.