|
Yeah, instance counting is easy. BTW: you could decrement the counter in a finalizer.
However reference counting is basically impossible, a reference can be copied without the class or object being aware of that.
Person person1=new Person();
Person person2=person1;
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Yeah, that's my point.
[Kayes]
|
|
|
|
|
That's a way. But consider the following. One object is constructed, but two references.
Person p = new Person();
Person q = p;
How to track this?
[Kayes]
|
|
|
|
|
you can't, there is nothing to support that in .NET
The GC is based on (a slightly conservative) reachability or "life" analysis, not on reference counting.
why would you need a reference count?
if only for one or a few classes of your own, you could try and implement it yourself, including an override for the = operator. Not sure you can get it all tight though.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Helloo Experts!!
I want to calculate difference between two dates(Day) and display that differnce date like 12\02\09,
In short,
current date:12\02\09
Dispaly date;11\02\09
help me!!
|
|
|
|
|
See Timespan class[^]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
you can try this,
DateTime d1 = DateTime.Today;
DateTime d2 = DateTime.Today.AddDays(1);
TimeSpan ans = d2.Subtract(d1);
If I didn't get your problem plz explain it.
Education is not a way to escape poverty — it is a way of fighting it.
|
|
|
|
|
|
public new static object GetIPictureDispFromPicture(System.Drawing.Image image)
{
System.Drawing.ImageConverter converter2 = new System.Drawing.ImageConverter();
byte[] arraybyt2 = (byte[])converter2.ConvertTo(image, typeof(byte[]));
System.Drawing.Image imageToConvert = System.Windows.Forms.AxHost.GetPictureFromIPicture(System.Windows.Forms.AxHost.GetIPictureFromPicture(image));
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
byte[] arraybyt = (byte[])converter.ConvertTo(imageToConvert, typeof(byte[]));
return System.Windows.Forms.AxHost.GetIPictureFromPicture(image);
}
The function receives a Image that needs to be converted to an ipicture. I found out that during change the image to a ipicture and back to image the size of the array of bytes are different. How come the size of the arraybyt1 and arraybyt2 are different. I'm creating a checksum of the array from bytes and therefor the checksum is also different?
|
|
|
|
|
I am not familiar with IPicture, and therefore this is very much a guess.
Perhaps Image stores data that IPicture doesn't, or vice versa. For example, different sized headers or one stores palette information and one doesn't.
Most image formats have their specifications out on the web somewhere, have a play with google.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I need to create a method that accepts a string as a parameter and checks whether this parameter is a valid SQL Server datatype or not. Can someone help please?
thanks
|
|
|
|
|
Hi,
Change the method parameter from String to SqlDbType.
himanshu
|
|
|
|
|
How about System.Enum.Parse ( typeof(System.Data.SqlDbType) , "datetime" , true ) ?
|
|
|
|
|
thanks it worked fine for my application
|
|
|
|
|
|
How can i load in a XmlDocument an xml file (from text file) that in the tag contain any type of char ? How can encode this ?
If my file contain char as "&" or "°" there is an exception (Xml.XmlException Errore durante l'analisi di EntityName).
I try with this but don't work:
Encoding enc = Encoding.ASCII;
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs,enc);
string response = sr.ReadToEnd();
XmlDocument xml = new XmlDocument();
xml.LoadXml(response);
fs.Close();
sr.Close();
The exception is Xml.XmlException Errore durante l'analisi di EntityName.
|
|
|
|
|
Well as far as I know it is not allowed to use all chars in entity-names. There is a strict rule for tag-names. Maybe you could post a bit of your xml-file, so that we can identify the problem.
Regards
Sebastian
|
|
|
|
|
The problem isn't the tag-names but their content.
The exception occur when in the content of a tag (<tag> abc & avc n° ) there are particular char as & or °
|
|
|
|
|
You could replace all special characters with their escape characters before reading the xml. Maybe this helps.
|
|
|
|
|
How can i replace it ? can you give me an example of code ?
|
|
|
|
|
Not the best method but maybe
response = response.Replace( "&", "&");
By the way, do you have an xml-declaration in your file (sort of <?xml version="1.0" encoding="UTF-8"?> )?
|
|
|
|
|
I dont' have an xml-declaration...however if i add it there is always the same exception.
To use replace i must know all possible incorrect char... i would like to find a method valid for all possible char that may occur in the file.
Edit:
if i use utf8 encoding and replace of &, program work well with my current file xml.
I hope in future don't occur another char that create same problem. I think that & is properly of XML standard and so cause this exception.
modified on Wednesday, June 17, 2009 8:14 AM
|
|
|
|
|
If the file doesn't contain a well-formed XML document you'll need to fix it.
|
|
|
|
|
For the moment i use utf8 encoding and replace all the & with &
What are the other possible char that may cause the Exception ?
|
|
|
|
|