|
Hi I’m working on a system that has 4 different types of client they have mostly the same attributes so I decided to create an interface IClient for them to implement and then just add the differing attributes as needed to each client class.
Now I get the Client information from a DB and Load them into a Generic dictionary
The class looks like so
[code]
class Class1<T> : Dictionary<int, T> where T:IClient
{
private IndemnityScheme scheme;
public Class1(IndemnityScheme scheme)
{
this.scheme = scheme;
}
public int Load()
{
// "procIndemnityClientSelect";
DataBaseAccess dba = new DataBaseAccess(this.scheme);
SqlDataReader reader = dba.LoadData("procPrsymClientSelect");
SmartDataReader smartReader = new SmartDataReader(reader);
while (smartReader.Read()) {
AceClient newClient = new AceClient(this.scheme);
newClient.Clientshort = smartReader.GetString("Client Short Name");
newClient.Clientname = smartReader.GetString("Client Name");
newClient.Clientref = smartReader.GetInt32("client ref");
newClient.AddressLine1 = smartReader.GetString("Address Line 1");
newClient.AddressLine2 = smartReader.GetString("Address Line 2");
newClient.AddressLine3 = smartReader.GetString("Address Line 3");
newClient.AddressLine4 = smartReader.GetString("Address Line 4");
newClient.AddressLine5 = smartReader.GetString("Address Line 5");
newClient.AddressLine6 = smartReader.GetString("Address Line 6");
newClient.Telephone = smartReader.GetString("Telephone No");
newClient.PostCode = smartReader.GetString("post code");
newClient.Contact = smartReader.GetString("Contact");
// newClient.Handler = smartReader.GetString("Handler");
newClient.Joindate = smartReader.GetString("Join Date");
newClient.Leavingdate = smartReader.GetString("leaving Date");
newClient.Salutation = smartReader.GetString("salutation");
newClient.Email = smartReader.GetString("Email");
newClient.Comments = smartReader.GetString("comments");
base.Add(newClient.Clientref, newClient);
}
smartReader.Close();
smartReader = null;
dba = null;
return base.Count;
}
}
[/code]
I call the class in my program like so
[code]
AceClient c = new AceClient(IndemnityScheme.ACE);
Class1<AceClient> cl = new Class1<AceClient>(IndemnityScheme.ACE);
cl.Load();
foreach (AceClient ac in cl.Values) {
System.Diagnostics.Debug.WriteLine(ac.Clientshort);
}
[/code]
Nothing fancy just want to loop throught the collection but on trying to complie I get an error.
This is the line of code that errors
[code]
base.Add(newClient.Clientref, newClient);
[/code]
Error 24 The best overloaded method match for 'System.Collections.Generic.Dictionary<int,T>.Add(int, T)' has some invalid arguments
Error 25 Argument '2': cannot convert from 'Prsym.AceClient' to 'T'
Can anyone tell me what I am doing wrong??
|
|
|
|
|
Does AceClient implement the IClient interface? This error can occur because the class violates the conditions of the generic (in this case where T implements IClient).
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks for the reply yes the AceCLient does Implement ICleint.
I was hoping that
class Class1<t> : Dictionary<int,t> where T:IClient
would mean the Dictionary Type would be of the Type of the instantiate calls so in my instanace the dictionary would be Dictionary<int, aceclient).
this="" does="" not="" seem="" to="" be="" happen="" i="" have="" been="" able="" work="" around="" this="" by=""
="" class="" class1<t=""> : Dictionary<int,iclient> where T:IClient
It just means if i wish to access the collection by a class that implements ICLient i have to do the following casting
((AceClient)col[1]).Temp;
where col is the collection and Temp is and exdened property of AceCLient Not found in IClient
|
|
|
|
|
I begin learn C# i create 2 class connect.cs and Dataacess.cs
in Dataacess class I want to using connect class like VB.net Imports a class but error
using Connect;
i don't understand
Tell me about please
Thanks
quan
|
|
|
|
|
using is for namespaces. If your classes have the same namespaes, you don't need it. In fact, imports works the same way.
Connect c = new Connect();
will create an instance of the connect class for you.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
hi,
I have create a custom user control.How can i create the control dynamicly and put into a array.
any hits are welcome,
thanks in advance
cocoonwls
|
|
|
|
|
List<myUserControl> ctrls = new List<myUserControl>();<br />
<br />
myUserControl ctrl = new myUserControl();<br />
ctrls.Add(ctrl);<br />
<br />
life is study!!!
|
|
|
|
|
Please see the fillowing link. I think this will help you.
http://www.codeproject.com/useritems/DynamicServerControls.asp
asd
|
|
|
|
|
Dear All,
I assign memory to a parameter to store some information. I start with the value null for that parametr. After usage, I set the value back to null, but the memory assign to the parameter is not released. How do I destroy the parameter ? Any help is , as usual , highly appreciated.
private FormNetworking _fo;
public void pbNetworking_Click(object sender, System.EventArgs e)
{
if (_fo == null)
{
_fo = new FormNetworking();
_fo.Show();
_fo.FormClosed += new FormClosedEventHandler(fo_Closed);
}
else
{
_fo.Focus();
}
}
public void fo_Closed(object sender, FormClosedEventArgs e)
{
_fo = null;
}
kind regards,
|
|
|
|
|
If your object has a DIspose method, call it first. Otherwise, you have to wait for the GC to do it's thing.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thank you so much for your input.
Unfortunately it didn't do the trick. I invoke :
_fo.dispose();
before closing the form but the memory is not released. Every time I open a new instance of the form, it adds a little bit ( about 8 k ) to the memory.
|
|
|
|
|
Welcome to a GC system. Memory is released sometime in the future, there's nothing you can do, and nothing to worry about. Still call Dispose, tho.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I guess you're right. Even unmanaged resources eventually have to rely on the GC to get cleaned up.
thx for your anwser , I won't worry then
|
|
|
|
|
As Christian pointed out, welcome to a garbage collected world. At some point after your object is disposed, the GC will eventually free the memory. Calling Dispose only helps mark the object as collectible.
Rick van Woudenberg wrote: Even unmanaged resources eventually have to rely on the GC to get cleaned up
Unfortunately, the GC does not know how to free unmanaged resources. That is the reason to call Dispose when you are done using the object.
For a more detailed look at how to implement Dispose , check out the following article:
http://www.codeproject.com/useritems/idisposable.asp[^]
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott Dorman wrote: Calling Dispose only helps mark the object as collectible.
That's incorrect. Calling Dispose has nothing to do with garbage collection, it is required only to release the resources held by the object immediately. The GC only checks for references to an object to find out if it's eligible for collection.
|
|
|
|
|
You are correct...that statement was inaccurate. However, when the GC does collect an object it will call the Dispose method if it hasn't already been disposed.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott Dorman wrote: However, when the GC does collect an object it will call the Dispose method
I guess you meant Finalize instead of Dispose.
|
|
|
|
|
Arrrrrgggggg!!!
Yes, I did. It's been a long day...and it's only half over. I guess that's what happens when you don't get more than a few hours of sleep the night before.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Yeah, one thing a lot of people miss is the Dispose/Finalise pattern.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hello,
To make sure if your class is really ready for the GC, call GC.Collect() just for testing (Of course its not recomended to leave it in your code).
It could also be possible that the FormNetworking instance holds a connection too an other custom class (for example over an eventhandler), and so the GC will not clear the memory!
I also would recomend too check youre code with .Net MemoryProfiler (freeware).
All the best,
Martin
|
|
|
|
|
Can any Body tell me what is Bug Tacking System.
|
|
|
|
|
It's a system, right, for tracking ( are you still with me ? ), bugs.
In other words, it's something you could easily have googled for, or gone to wikipedia, it's a system that is used to keep track of known issues in your software, and when/how you fix them
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thankx for replying Christian Graus.
|
|
|
|
|
Hi boys & girls,
I would like to implement automatic updates to my application (which is in C#).
I’m quite confused, I heard that there is ClickOnce\ Updater Application Block built in .Net 2005, is it correct?
How do I use it?
Were can I find relevant tutorials?
In the MSDN site I could find only the Updater Application Block for .Net 2003
Thanks,
Gil
May the source be with you
|
|
|
|
|
I have been working on trying to write a directory watcher service.
One of the requirments is that it be able to watch multiple
directories, not sub directories of one parent directory, but just
multiple directories.
Using FileSystemWatcher in .Net
Thanks in Advance
Hari
|
|
|
|