Find out if a list contains two objects with the same value

I have a class which contains three values,

public class hitOBject {
	public string v1;
	public float v2;
	public float v3;
}

I dynamically create these objects during runtime which get stored in their own list.

 List<hitOBject> Detected = new List<hitOBject>();

However, when a new object is added to this list, I first need to check if if there is already a list which contains a a duplicate value.
For example…

if I have 2 hitObjects

 obj1            obj2 
 v1 = bob        v1 = bob 
 v2 = 1f         v2 = 3f     
 v3 = 2.5f       v3 = 3.5f  

and if I want to check wether V1 already exists in the list is there a method to do this?

I know that if it was a duplicated object I could just do the following code?

if(!Detected.Contains(object))

but as Im looking for a sub value this wont work?

Can anyone point me in the right direction?

This sound like a job for a dictionary!

Dictionaries are Key Value Pairs, and Keys are Unique. So you can do something like.

 public class hitOBject {
     public string v1;
     public float v2;
     public float v3;
 }

Then you create dictionary out of it like so.

using System.Collections.Generic

Dictionary<string,hitOBject> myDic = new Dictionary<string,hitOBject>();

to put things in myDic you do

if(!myDic.contains("herps"){
  myDic.Add("herps",someHitObject); // myDic does not have herps
}
else{
  myDic["herps"] = someHitObject;  // myDic DOES have herps so change its hitObject to something new. 
}

To access the value of a entry just do

myDic["bob"]

To iterate through the Dictionary go

foreach (KeyValuePair<string,hitObject> kvp in myDic){
    Debug.Log(kvp.value.v2);  //will output v2 value, float in this case 
    Debug.Log(kvp.key);   // will output dictionary name
}

WUCC

public bool hasDuplicate()
{
foreach( hitOBject h in Detected)
{
string val = h.v1;
foreach( hitOBject h2 in Detected)
{
if(h2 == h)
continue;
if(val == h2.v1)
return true;
}
}
return false;
}

it is rather intensive to loop in this way however, use sparingly