I have a class Referrals. When you create an object in the class, it checks that the input strings are unique (and therefore never allows duplicate objects). But when I find that input string str1 is equal to that of a previously created object, instead of creating a new object or just returning false, i want to change a property of the already created object. But i can't figure out how to do this, as the method has no way of knowing the name of the object. But I know something unique about it! I feel like this must be enough to somehow call it, and do what I need to do.
Any ideas?
THANKS!
Here is the class:
public class Referral
{
public class Referral
{
public string URL;
public Dictionary<string, int> Keywords = new Dictionary<string, int>();
private static Dictionary<string, string> URLs = new Dictionary<string, string>();
private int HowManyURLs;
private bool UniqueURL;
private bool UniqueKeyword;
public Referral(string MyURL, string MyKeyword, int MyOccurrences) //Constructor
{
if (HowManyURLs == 0)
{
URL = MyURL;
Keywords.Add(MyKeyword, MyOccurrences);
URLs.Add(MyURL, MyKeyword);
HowManyURLs++;
}
else
{
// RESET FLAGS
UniqueURL = true;
UniqueKeyword = true;
for ( int i = 0; i < HowManyURLs; i++ )
{
if ( URLs.ContainsKey( MyURL ) )
{
// TRIP URL FLAG
UniqueURL = false;
// NOW CHECK KEYWORDS OF URL << THIS IS WHAT I CAN'T DO!
if ( URLs.ContainsKey( MyKeyword ) )
{
// TRIP KEYWORD FLAG
UniqueKeyword = false;
// ADD TO OCCURRENCES
// Referral[MyURL].Occurrences += MyOccurrences;
}
}
}
// IF BOTH FLAGS TRUE
if ( UniqueURL == true && UniqueKeyword == true )
{
URL = MyURL;
Keywords.Add(MyKeyword, MyOccurrences);
URLs.Add(MyURL, MyKeyword);
HowManyURLs++;
}
}
}
}