|
Strange, both work for me
Hashtable myHashTable = new Hashtable();
HashKey myHashKey = new HashKey("keyName");
myHashTable.Add(myHashKey, 4);
value = myHashTable["keyName"];
value = null;
value = myHashTable[myHashKey];
after both calls "value" is 4. I inserted the "value = null" to see whether the second call will change "value" at all.
You might want to add another if-clause like else if(obj is String) return _name.Equals((String)obj) into the Equals method.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
It doesn't work for me. I think it can't work because in case of asking
value = myHashTable["keyName"];
string.Equals() is called which is can never returns true when asked about equality with HashKey instance, right?
myMsg.BehindDaKeys = "Jerry Maguire";
|
|
|
|
|
But you do an object comparison with the _name-string of your hashkey instance, so you compare two strings in case object is a string.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yep, but I guess the problem is that in case of the string hashtable key not the Hashkey.Equals() method is called. Instead it calls the string "keyName".Equals(hashKeyInstance) which returns false.
So in case of asking the value with the string key, it works the other way round with calling Equals(). Is this correct?
Thank you very much for your efforts.
myMsg.BehindDaKeys = "Jerry Maguire";
|
|
|
|
|
I am trying to serialize and deserialize C# objects to an SVG file. I need to specify some custom types and have these serialized as attributes (e.g. fill = '#CCFF00'). However I cannot figure out how to serialize types other than the built-in types (string, int etc).
Right now my code looks like this (and it works):
<br />
private SVGColor m_Fill = new SVGColor(Color.White);<br />
[XmlAttribute("fill")]<br />
public string svg_fill {<br />
get {<br />
return m_Fill.ToString();<br />
}<br />
set {<br />
m_Fill = SVGColor.Parse(value);<br />
}<br />
}<br />
[XmlIgnore]<br />
public Color Fill {<br />
get {<br />
return m_Fill.Colour;<br />
}<br />
set {<br />
m_Fill.Colour = value;<br />
}<br />
}<br />
But it seems as though there should be a way to implement an interface for SVGColor that would allow the parser to automatically serialize & deserialize it based on its ToString & Parse methods. Then one could replace all this code with:
[XmlAttribute("fill")] public SVGColor Fill;
Is this possible??
|
|
|
|
|
I am new to programming in C# so please be patient. How do i read (in C#) the status of a port to trigger an event. For example.... when door opens, trigger switch high, (or low) through optio-coupler device via serial port to control stereo power on, or answering machine play, etc.
Throw me a line and we'll help each other.
|
|
|
|
|
You might want to have a look at this[^] series on Coding4Fun.
It'll save you having to write device drivers to get at the low-level details of a serial port, something that is abstracted from your code by Windows.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am trying to set sessions on the sql server in my web services. After running some scripts on sql server and setting the config files, how do I actually populate the sql server session tables? I would also like to save the data (from the user's search results) from several sessions in the session tables. Can somebody help me with this. Thanks.
Mina
|
|
|
|
|
i've selected some rows from the database and populate my DataSet.
After i've deleted some rows and update them.
Now i want to update the original Database with changed on the dataset.
i've used this code, but it is not good becouse it need an insert comand:
conn = new OleDbConnection(conn_string);
string selction_string = "Select * FROM myTable";
OleDbDataAdapter adapter = new OleDbDataAdapter(selction_string, conn);
conn.Open();
adapter.Update(mydataSet); <-----
conn.Close();
|
|
|
|
|
Yes, you need to provide the SQL to do the insert. What's wrong with that ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
so the dataAdapter doesn't understand automatically what is changed and make the correct update automatically?
If so, what is a possible SQL statement to do that (how have i to change the code)?
|
|
|
|
|
|
Honestly i don't wanted you to write code for me, but i want to know what is the correct InsertCommand i've to indicate for the dataAdapter.
I don't think it can be a: "INSERT INTO ..." becouse i don't know what are new rows inserted.
Then also rows deleted or modified.
|
|
|
|
|
Sasuko wrote: I don't think it can be a: "INSERT INTO ..." becouse i don't know what are new rows inserted.
It *has* to be INSERT INTO, what else would work ? The rows are marked in the dataset as being changed/added/deleted. I suspect if you provided SQL that selected specific columns, what you're doing may work, but like I said, I would iterate through the dataset myself and write a stored proc that takes XML and uses OPENXML to do bulk deleting/updating/inserting.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
so i've get all the row added to the datase then creating a SQL insert statement and past it to the datadapter?
|
|
|
|
|
You need to do what Wjousts said. I thought you did, but the sample I linked to didn't seem to have that bit, so I figured it could be inferred ( which makes sense, the table knows the columns, and it knows which rows are new ).
If the dataadapter works, then you wouldn't need to work out for yourself what rows are changed/new. I'm saying I don't use the dataadapter.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Of course it's INSERT INTO...
You need something like this:
MyDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO MyTable (MyField1, MyField2, ....) VALUES (?, ?, ...)",MyConnection);
MyDataAdapter.InsertCommand.Parameters.Add(new OleDbParameter("MyField1",int,0,"MyDataTableField1");
...
And so on. When you do the update the DataAdapter knows which rows are new and substitutes the parameters (the ? in the SQL statement) with the real values in your DataTable according to the mappings in the InsertCommands Parameters.
You might also want to do the Update and Delete commands as well if you actually want updates and deletes to be possible.
|
|
|
|
|
Hi All,
I want to developed application for automatically detecting Video format .can any one help regrding above problem.Pls do reply on frum or personally mail me .
Thanks & Regards,
Amit More
amit.more@pictureal.net
|
|
|
|
|
Reading the FOURCC-code from the header of the video will you give you a lot of information. You can then use a lookup-table to check agains the correct format.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I've created an application that use panels with image inside. i use these panels as custom buttons or just for graphic.
When the application start and these controls are drawed it appear for a bit black (during on paint event) then are drawed, it happen also if i use normal textbox xp style, they are black then became normal when the application is ended to load.
Why it happen to my application.
How can avoid it?
Please help me to understand where is the bug.
|
|
|
|
|
I think that that is a flicker...
You must enable double-buffering on your controls.
Put this in your constructor:
this.SetStyle ( ControlStyles.OptimizedDoubleBuffer, true );
this.SetStyle ( ControlStyles.AllPaintingInWmPaint, true );
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hello peoples,
I wonder if it is possible to create an instance of an object which type
is stored in a "System.Type" variable:
Example:
<br />
MyClass obj1 = new MyClass();<br />
System.Type type = obj1.GetType();<br />
((type) obj2) = new type();
I could write a huge "switch case" block and then switch through all
existing types, but it would be pretty inflexible and also bad style.
Any ideas ?
|
|
|
|
|
Activator class can help in your case
<br />
System.Type type = typeof(MyClass);<br />
MyClass obj = (MyClass)Activator.CreateInstance(type);<br />
DevIntelligence.com - My blog for .Net Developers
|
|
|
|
|
Hello tarasn,
the issue here is - I have to know the type(e.g. MyClass) on the left side of given expression and in the casting brakets too:
<br />
MyClass obj = (MyClass)Activator.CreateInstance(type);<br />
But in certain situations the type is unknown... Assuming I have to "unbox" an object of type "System.Object" and I also can get its Type using object.GetType() and store it in a variable:
<br />
System.Type type = object.GetType(); <br />
How can I create a new instance of whatever is boxed in this object?
Maybe some trick with StringBuilder or so...
-- modified at 10:38 Tuesday 17th January, 2006
|
|
|
|
|
Surely you cannot cast but you can still create the object:
System.Type type = object.GetType();<br />
object newObject = Activator.CreateInstance(type);
Note that this only works for objects whose classes define an constructor with no arguments.
|
|
|
|