|
Hi,
I have read in 1 book that the STATIC function Object.Equals() check the object values and Object.ReferenceEquals() check their references.
For Ex- Suppose i have a user defined class - Person
Person p1 = new Person( 1,"ABC");
Persion p2 = new Person( 1,"ABC");
Object.Equals( p1, p2 ) -> returns true. // compares the state
Object.ReferenceEquals( p1,p2) -> returns false.// compares the reference.
The output should be like this as specified in that book. But am not getting like this. We cant overide static functions too. Any Idea? It would of great help.
Regards
|
|
|
|
|
|
You'll have to override the protected method Equals inherited from Object.
This flavor is my own personal favorite, note the use of the private Equals.
. I also like overloading the == operator.
namespace PersonTest {
class Program {
static void Main(string[] args) {
Person p1 = new Person { Member = "ABC", OtherMember = 1 };
Person p2 = new Person { Member = "ABC", OtherMember = 1 };
Console.WriteLine(Object.Equals(p1, p2).ToString());
Console.WriteLine(Object.ReferenceEquals(p1, p2).ToString());
Console.ReadLine();
}
}
public class Person {
public String Member { get; set; }
public Int32 OtherMember { get; set; }
public override Boolean Equals(Object obj) {
return obj is Person ? Equals(obj as Person) : false;
}
private Boolean Equals(Person obj) {
if (Object.ReferenceEquals(this, obj)) return true;
if ((obj == null) || (this == null)) return false;
return obj.Member == this.Member && obj.OtherMember == this.OtherMember;
}
public override int GetHashCode() {
return base.GetHashCode();
}
}
}
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Hi,
If we are overriding the protected method Equals(), then whats the difference between the usage of virtual function Equals() and static function Equals defined in the Object class.
|
|
|
|
|
The static method Equals(object.object) uses the virtual method Equals(object). You just have to override the Equals(object) method in your Person class.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello,
I have, on a PC, two Network Adapters.
I need to test the quality of these interfaces, with a cross link.
I have written a small program in C# with a client socket and a server socket.
But I want to be sure that exchange is going on the cable, and NOT inside the network layers of the PC.
So I want to bind the client socket and the server socket each to one of the interfaces.
The function I want to use is in the following code :
Socket xPortSend;
//...
byte[] AdapterId = ????
int iRet = xPortSend.IOControl( IOControlCode.BindToInterface, AdapterId, null );
1) I don't know how to find the Adapter Id of each network interface ?
2) Which is the exact synthax to use with the function "IOControl" ?
Some samples on this call will be very helpfull ?
Best regards.
|
|
|
|
|
hello ,
is it possible to create a c# application that detect if the PC is shuting down
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
what for you want that application ? if PC shuts down ,application also shuts down
Koushik
|
|
|
|
|
ellllllllie wrote: hello ,
is it possible to create a c# application that detect if the PC is shuting down
Yes. There I've answered your question.
|
|
|
|
|
How can add a property to a existing .NET control. For eg: Add a property "AllowNumbers" to textbox control.
Thanks
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
derive a new class from it and add your property
public class MyTextBox : TextBox
{
public MyTextBox() : base()
{
}
private bool allowNumbers = false;
public bool AllowNumbers
{
get{ return this.allowNumbers; }
set{ this.allowNumbers = value; }
}
}
|
|
|
|
|
Thanks a lot.
I am facing one more issue.
I have created a user control, but when I add it to the form from the toolbox I get following code in the designer file:
this.usercontrol1 = new usercontrol.usercontrol();
instead of
this.usercontrol1 = new usercontrol();
This is causing build errors.
Any help with this ?
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
Put your control in the same namespace...
|
|
|
|
|
The form and the user control share the same namespace
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
What kind of error ?
The compiler returns an error message, if error comes.
|
|
|
|
|
Line of code giving error:
this.dataGridWrapper1 = new DataGridWrapper.DataGridWrapper();
error description:
The type name 'DataGridWrapper' does not exist in the type 'DataGridWrapper.DataGridWrapper'
DataGridWrapper is the namespace and also the class name for the usercontrol.
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
That means, there is something wrong with DataGridWrapper namespace or DataGridWrapper class. Not in usercontrol.
Please rename your namespace, not the same name with your class.
Then just put the right namespace. That means, in namespace "DataGridWrapper" there is no class with the name "DataGridWrapper"....
|
|
|
|
|
great it worked!!!
stupid me
probably i had confused .net by same names
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
Im well aware that there are a gazillion of AOP inspired samples out there that show how to intercept ContextBoundObject.
ServicedComponent inherits ContextBound, but none of those examples works when applied to SC.
Have anyone done this?
I pretty much only want to log parameters and do some basic serup when a method is called.
|
|
|
|
|
A database having two tables, Company and Cust.
Company feilds : Cid, Cname
Cust Feilds: custId, custName, Cid(same as Company)
I bound the Company:Cname to a combobox,
I want to write a query like:
"select * from Cust where [Cid]= ???"
???=(here the Cid of selected Cname from comboBox)
how to get the corresponding Cid feild of combobox selected Cname??
|
|
|
|
|
Set Cid as the valuemember for the combo and Cname as the display member. Then the where clause will become - "where Cid = combobox.selectedvalue"
Hope it helps.
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
Thanks for replying.
d@nish wrote: where Cid = combobox.selectedvalue"
I also had tried this, but its giving error "Datatype mismatch in criteria exprssion"
Also when i debug the query, comboBox.SelectedValue gives the index value of selected item, not the Cid feild value from Company table.
any suggestion or link u can fwd me.
|
|
|
|
|
assuming you've set the DataValueField member when databinding...
<br />
combobox.SelectedValue<br />
|
|
|
|
|
Eduard Keilholz wrote: assuming you've set the DataValueField member when databinding...
I had set the comboBox.DisplayMember = "Cname" (name of company)
comboBox.Valuemamber="Cid" (id of company)
but still not ok??
Eduard Keilholz wrote: combobox.SelectedValue
I also had tried this, but its giving error "Datatype mismatch in criteria exprssion"
Also when i debug the query, comboBox.SelectedValue gives the index value of selected item, not the Cid feild value from Company table.
any suggestion or link u can fwd me.
|
|
|
|
|
this code works fine for me:
this.comboBox1.DataSource = this.dataGridWrapper1.table;
this.comboBox1.ValueMember = "ID";
this.comboBox1.DisplayMember = "DT";
:
:
:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
string s = this.comboBox1.SelectedValue.ToString();
}
I get the id corresponding to the selected dt
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|