How to compare UnityEngine.Resolution with itself?
The code in question:
foreach (Resolution res in Screen.resolutions)
{
reslist.Add(res.ToString());
if (Screen.currentResolution == res)
{
index = Array.IndexOf(Screen.resolutions, res);
}
}
The If-line produces the following error message:
error CS0019: Operator '==' cannot be applied to operands of type 'UnityEngine.Resolution' and 'UnityEngine.Resolution'
This doesn't make sense to me. Can anybody please help?
Edit: reslist is a local List<string>
Answer by Toon_Werawat · Apr 02, 2016 at 12:01 PM
You can use alternative. Here
First. Use System linq
using System.Linq;
Then replace all for each code. With this code.
Screen.resolutions.ToList().Foreach(res => reslist.Add(res.ToString()));
index = Screen.resolutions.ToList().IndexOf(Screen.currentResolution);
Thank you, this works. A closing bracket for the Foreach() method is missing though.
Also, you forgot to ToList() the array before using IndexOf().
Oops! I though I already wrote ToList(). ._.
Let's me fix that. Incase if anyone else need it
Uhhmmm.... I don't mean to be nit-picking, but the ToList in the second line wants it's brackets. :)
Oh. Ok I'll fix it ._. It really hard to write code. Without auto complete like in Visual Studio
Your answer
![](https://koobas.hobune.stream/wayback/20220612074022im_/https://answers.unity.com/themes/thub/images/avi.jpg)