|
They're also overridable in your code. Did you check the example? There's a link at the bottom of the page.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
And we'd need to see your code where you're overloading these operators to tell you what you're doing wrong.
|
|
|
|
|
|
As Eddy states, those aren't Unary operators. This would indicate that these aren't the ones that are causing you problems. Could you post a sample that shows the code that the compiler is complaining about?
|
|
|
|
|
OK, thanks guys for the links, but I've already seen this. Problem is that I'm trying to convert simple class from C++ to CS. Here is the code:
class SOME_API SomeClass
{
public:
bool operator==( const SomeClass& Other ) const
{
return Index == Other.Index;
}
bool operator!=( const SomeClass& Other ) const
{
return Index != Other.Index;
}
private:
int Index;
};
Is there any chance to convert this to CS without writing a bunch of code?
|
|
|
|
|
A rough untested example of how I do this for a class (it's much simpler for a struct as it can never be null ):
public class SomeClass : IEquatable<SomeClass>
{
private int index;
public SomeClass(int index)
{
this.index = index;
}
public static bool operator ==(SomeClass instance, SomeClass other)
{
if(object.ReferenceEquals(instance, other))
return true;
if(object.ReferenceEquals(null, instance) || object.ReferenceEquals(null, other))
return false;
return instance.index == other.index;
}
public static bool operator !=(SomeClass instance, SomeClass other)
{
return !(instance == other);
}
public int Index
{
get { return index; }
}
public override bool Equals(object obj)
{
return Equals(obj as SomeClass);
}
public bool Equals(SomeClass other)
{
if(object.ReferenceEquals(null, other))
return false;
return index.Equals(other.index);
}
public override int GetHashCode()
{
return index;
}
}
And a struct:
public struct SomeStruct : IEquatable<SomeStruct>
{
private int index;
public SomeStruct(int index)
{
this.index = index;
}
public static bool operator ==(SomeStruct instance, SomeStruct other)
{
return instance.index == other.index;
}
public static bool operator !=(SomeStruct instance, SomeStruct other)
{
return !(instance == other);
}
public int Index
{
get { return index; }
}
public override bool Equals(object obj)
{
if(obj is SomeStruct)
return Equals((SomeStruct)obj);
return false;
}
public bool Equals(SomeStruct other)
{
return index.Equals(other.index);
}
public override int GetHashCode()
{
return index;
}
}
|
|
|
|
|
Unary operators require one parameter, so it's assuming that the operator should be a unary one as you are only supplying one parameter.
The operators you have listed are binary operators, so require two parameters.
See my example in my other post and my article An Introduction to Operator Overloading in C#[^]
|
|
|
|
|
Thanks for the snippets DaveyM69 - I've ended up with something similar. For now, to compare I'm using GetIndex(), but my converted code is constantly growing. Didn't know that CS is so much more complicated...
Thanks again...
|
|
|
|
|
I don't believe C# is much more complicated with this; I think the real difference is that you'd typically let the overloaded operators be member functions in C++ and C# wants them to be static functions. So if you rewrite your C++ code to the static overloading, then you're already having the same code in C# and C++.
|
|
|
|
|
Is that possible to open two mdi parent form in one(same) mdi container???? And if yes then how????
Please Give me the answer.......
|
|
|
|
|
keyur_raval wrote: Is that possible to open two mdi parent form in one(same) mdi container
Not at the same time. You can change what the MDI Parent is, but you can't have two of them together.
|
|
|
|
|
1.How to record the video from a System.Windows.Forms.Panel?
1.How to record the video from a System.Windows.Forms.Panel By Use Handle?
|
|
|
|
|
Your reposted question is no better phrased than the question you posted 34 minutes ago.
You should read this[^]
|
|
|
|
|
Please Write a better answer
|
|
|
|
|
makhondi wrote: Please Write a better answer
As a general rule, the quality of the answer you get is directly proportional to the quality of the question asked. Take your question for example. It's vague, broad in scope, not even a question, demonstrates lack of any research, does not demonstrate any effort on your part and does not make any sense to begin with. As a result you are going to get vague, broad answers that are probably not going to be of much help.
Bottom line: you want better answers then ask better questions.
|
|
|
|
|
I'm confused about your question. You normally wouldn't use a panel to display video information, so how are you actually displaying the video there?
|
|
|
|
|
...and if you've already got the video displaying in your app, why would you need to record it again?? Or is this live video from a camera or other source, such as YouTube??
|
|
|
|
|
I have a project where I need to be able to make film (.avi) of panel.
For example:
SaveAvi(panel1);
|
|
|
|
|
well, we're not exactely mind-readers here, and you give us sfa on what you've tried, and what your issues really are ..
so I suggest you start here (see link), and when you have a specific issue, post back a decent question with/about a code issue
A Simple C# Wrapper for the AviFile Library[^]
'g'
|
|
|
|
|
Okay, so you have a basic requirement. You now need to flesh this out some more. Once you have done that, you should be able to start coding your application.
|
|
|
|
|
btw 'Help !' really ? .. no please ?? manners, manners, manners - old proverb 'its easier to catch flies with honey than vinegar'
'g'
|
|
|
|
|
Garth J Lancaster wrote: 'its easier to catch flies with honey than vinegar'
Who yer goin' an' callin' flies?
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hello, I'm doing a project to send information from multiple serial ports over TCPIP network.
The approach I am using is as follows:
Use BackgroundWorker for each serial port that is used to capture the information received.
I use a common method to treat the information received and stored in a queue using locks.
Queue _cola = new Queue();
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker bw = sender as BackgroundWorker;
string port = (string)e.Argument;
SerialPort sprt = new SerialPort(port);
sprt.BaudRate = 4800;
sprt.Parity = Parity.None;
sprt.StopBits = StopBits.One;
sprt.DataBits = 8;
sprt.Handshake = Handshake.None;
try
{
sprt.Open();
}
catch (Exception)
{
MessageBox.Show("Check port");
return;
}
while (!bw.CancellationPending)
{
string indata = sprt.ReadLine();
lock (_cola)
{
_cola.Enqueue(indata);
}
BeginInvoke((Action)(() = UpdateGraph(port)));
}
sprt.Close();
}
private void UpdateGraph(string port)
{
lock (_cola)
{
string text = Leer();
rtbOutput.AppendText(text );
rtbOutput.ScrollToCaret();
}
}
I found that if I open several ports and FIFO is slower getting data extracting data, the program is "locked." So far all I do is get the information even RichTextBox, but the purpose is to send this data via socket to another computer.
I understand that I should make a thread to avoid these locks but how should do so within the BackgroundWorker?
modified 13-Mar-13 5:44am.
|
|
|
|
|
Sir i just wanted to know the code for K-means Clustering on text documents !!
As the code is available in C#!
but I am not able to get it!
and I am new to this site!
So can anybody help me please!
Thanks a lot!
|
|
|
|
|
sunny funny wrote: I am new to this site!
And what does that have to do with being able to Google[^]?
|
|
|
|