is this type of thing ok.
namespace myclass
{
class set
{
List
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
John Mieske9 reputationPosted May 4, 2011, 9:09 AM EDT
From what I am seeing your calling this :
set tempSet = new set();
INSIDE of the class that its supposed to be for.
Your class :
class set
{
public set union(set passedSet)
{
//do stuff
return tempSet;
}
}
you cannot set it up like that. Now if your calling from another class :
class Program
{
set tempSet = new set();
test = tempSet.union();
}
then it should work just fine. Keep in mind, you have to setup what union is going to return. in other words, how you are defining 'test' in this above example.
VulpesRank #55 · 29.2K reputationPosted May 4, 2011, 9:44 AM EDT
Any error you're getting must therefore be caused by something else. Notice, in particular, that the set class should be declared to be public if you want to access it from a client of the dll.
John Mieske9 reputationPosted May 4, 2011, 9:55 AM EDT
using System;
using System.Collections.Generic;
namespace myclass
{
class set
{
List<object> mList;
//constructors and stuff
public set union(set passedSet)
{
set tempSet = new set();
//do stuff
Console.WriteLine("Creating a union ...");
return tempSet;
}
}
class Test
{
static void Main()
{
set s1 = new set();
Console.WriteLine(s1);
set s2 = new set();
Console.WriteLine(s2);
set s3 = s1.union(s2);
Console.WriteLine(s3);
Console.ReadKey();
}
}
}
OUTPUT :
myclass.set
myclass.set
Creating a union ...
myclass.set
mList shows not being used.. but other then that it works.
Sam HobbsRank #107 · 20.5K reputationPosted May 4, 2011, 10:03 AM EDT
namespace _121172
{
class set
{
public set(string comment)
{
Console.WriteLine(comment);
}
public set union()
{
set tempSet = new set("union");
return tempSet;
}
}
class Program
{
static void Main(string[] args)
{
set set1 = new set("initial");
set set2 = set1.union();
}
}
}
VulpesRank #55 · 29.2K reputationPosted May 4, 2011, 10:06 AM EDT
If you don't override it, the ToString() method which all classes inherit from System.Object displays the fully qualified name of the class i.e. myclass.set in this example. Console.WriteLine() automatically applies the ToString() method to its argument if you don't call it explicitly.
John Mieske9 reputationPosted May 4, 2011, 10:06 AM EDT
List
VulpesRank #55 · 29.2K reputationPosted May 4, 2011, 10:13 AM EDT
John,
No problem :)
Andrew FensterRank #983 · 2K reputationPosted May 4, 2011, 11:15 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 4, 2011, 11:43 AM EDT
Both of these have UnionWith, IntersectWith, ExceptWith and SymmetricExceptWith methods built in, silently ignore attempts to add duplicates and are lightning fast in operation.