|
THe problem is I don't know what you're trying to do.
You CAN NOT overload the = operator since that's an assignment.
You CAN overload the == operator because it's a comparison operation.
BUT! Your code says you want to overload the assignment, which you CAN NOT do, and frankly there's no reason to!
So which is it???
|
|
|
|
|
Now I've got it. I thought there is a possibility to do so and now I can see there isn't. Thanks Dave
|
|
|
|
|
Are you trying to assign a to b here?
|
|
|
|
|
Yes, I want to do that but I've got that there is not such a possibility for the "=" operator, according to what Dave was trying to tell me.
|
|
|
|
|
I can't see much sense in trying to assign a ComplexNumber from two others like this. Do you really mean it to be the summation of the two complex numbers to form the new one? If so, you would override the + instead. Have a look here[^] for details.
|
|
|
|
|
No as I said before, I somehow misunderstood the whole thing. By the way thanks for your attention and guidance
|
|
|
|
|
You should typically implement a function Clone that will create a copy of your class. See MSDN documentation for IClonable .
public ComplexNumber Clone()
{
return new ComplexNumber { Real = this.Real, Imagine = this.Imagine };
}
By the way if you want to implement IClonable , it would be preferable to use explicit interface implementation so that your regular Clone function could returns a ComplexNumber (not sure if it still necessary with recent C# compiler).
Philippe Mori
|
|
|
|
|
I guess you are a C++ programmer (your user name further reinforces that impression). In C#, you cannot override assignment; a = b for a reference type will always assign a to exactly the same reference as b, and it's not possible to change this behaviour. (I think this is good because it means you know what a line is doing, whereas hiding copying in = requires you to know things about the class you're using.)
If you want to create copies of an object, you should implement ICloneable (but read this[^]), a copy method (e.g. public ComplexNumber Copy() { ... } ) and/or provide a copy constructor (i.e. a constructor that takes a ComplexNumber).
|
|
|
|
|
You're completely right. I should try that instead. And by the way, I know there is a function in C++ called atoi but It has another meaning to me. It actually represents my slogan in a short form which is the same with that function's name!
Thanks for your help
|
|
|
|
|
atoi_powered wrote: I made a class for Complex Numbers
IMO you got a wrong starting point, special number systems (such as complex) is something I would implement as a value type (i.e. a struct), not a class. That would make your "instances" immutable, and it would remove the problem of assignment.
|
|
|
|
|
That's right! Thanks
|
|
|
|
|
you're welcome.
|
|
|
|
|
Is there a way to add a variable to a variable name reference? I'm trying to cut out a rats nest of if statements. When I searched, I found this but it didn't look like what I want: http://www.windows-tech.info/1/ae8c74ec5a29a601.php[^]
This is a code snippet to get an idea of what I'm talking about:
foreach (Shift shift in shiftArr)
{
if (shift.shift == currentShift)
{
if (programResult == 0)
{
shift.NG_Count++;
tb_Shift_$(currentShift)_Count_NG = Convert.ToString(shift.NG_Count);
}
else
{
shift.good_Count++;
tb_Shift_$(currentShift)_Count_G = Convert.ToString(shift.G_Count);
}
}
}
|
|
|
|
|
Well, that looks almost like you are trying to create a list of Count_NG and Count_G items. Perhaps that might help.
|
|
|
|
|
I already have them in a struct according to shift. Is there a way to use the currentShift variable to add the data to the text box? Maybe I can add the tb variable name to the struct? But then that would be changing in name every shift and not fit in with the code to process the G/NG per shift. I have 3 different tb's, one for each shift, for each G/NG count. The struct looks like this:
[StructLayout(LayoutKind.Sequential)]
public class Shift
{
public char shift;
public int good_Count = 0;
public int NG_Count = 0;
}
|
|
|
|
|
You cannot modify a variable name at runtime to point to a different value.
Perhaps a List or a Dictionary would be a better choice.
|
|
|
|
|
So you have variables called tb_Shift_1_Count_NG, tb_Shift_2_Count_NG etc? Surely you could call them tb_Shift[1].Count_NG ... and have a list of Shift objects instead of a whole bunch of variables.
|
|
|
|
|
I'd love to implement it that way, except tb_Shift_A_Coung_NG and tb_Shift_B_Count_NG are the names for the textbox. I don't think I can use an array for those, can I?
|
|
|
|
|
You can have an array (or list) of textboxes. That's not a problem.
|
|
|
|
|
I've implemented a tabbed browser that inherits from IWebBrowser2 and takes advantage of the BeforeNavigate2 and NewWindow3 events. When navigating to a new window, the event is trapped and the new window is sent to a new tab.
using System;
using System.Windows.Forms;
namespace BrowserTests
{
public partial class CustomBrowser : Form
{
public CustomBrowser()
{
InitializeComponent();
}
private void CustomBrowser_Load(object sender, EventArgs e)
{
this.CreateTabBrowser();
}
private void button1_Click(object sender, EventArgs e)
{
(this.tabControl1.SelectedTab.Tag as WebBrowser).Navigate(this.textBox1.Text);
}
private WebBrowser CreateTabBrowser()
{
TabPage tab = new TabPage();
this.tabControl1.TabPages.Add(tab);
this.tabControl1.SelectedTab = tab;
WebBrowser web = new WebBrowser()
{
Parent = tab,
Dock = DockStyle.Fill,
Tag = tab
};
tab.Tag = web;
SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;
axWeb.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(axWeb_BeforeNavigate2);
axWeb.NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWeb_NewWindow3);
return web;
}
void axWeb_BeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
{
}
void axWeb_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
{
WebBrowser web = this.CreateTabBrowser();
SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;
ppDisp = axWeb.Application;
}
}
}
Some pages are trying to navigate to a new window marked as a frame: Site With Example Behavior
(second link is what I'm trying to replicate). Click the link, it opens a new window/tab... switch windows/tabs, click the same link, it should now navigate to the other window/tab that was just created. However, since each tab window is a new browser, the pages cannot find the frame to navigate to and it results in a new window every time, not just the first time.
I've tried the following modification but I don't have a reference to the new window's frame name...
void axWeb_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
{
foreach (TabPage tabPage in this.tabControl1.TabPages)
{
WebBrowser web = (WebBrowser)tabPage.Tag;
SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;
if (web.Document.Window.Name == "targetFrameName")
{
ppDisp = axWeb.Application;
this.tabControl1.SelectedTab = tabPage;
return;
}
}
WebBrowser web = this.CreateTabBrowser();
SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;
ppDisp = axWeb.Application;
}
If I hard code the name of the target frame on various sites that I know of, the navigation gets sent to the existing frame like it should and does not create a new window.
Anyone know how I can get the target frame name of a new window?
Thanks!
|
|
|
|
|
Hello there!
I have a third party web service that was written in PHP. I've added the web reference to visual studio and the methods take an object[] as the parameter.
Now according to their documentation if I were to create this client in php it would look something like this for the object[]:
$params = array(
‘username’ => $user,
‘password’ => $pass,
‘param1’ => $param1_value,
);
How do I create this in C#? I can't do Dictionary<string, string=""> because I can't convert that to an object[].
|
|
|
|
|
|
I tried your suggestions:
Custom Class:
class MCInfo
{
public string username { get; set; }
public string password { get; set; }
public string supportname { get; set; }
}
Linq:
List<MCInfo> info = new List<MCInfo>();
info.Add(
new MCInfo()
{
username = "administrator",
password = "testing",
supportname = "BLAH BLAH"
});
var results = (from n in info
select new
{
username = n.username,
password = n.password,
supportname = n.supportname
}).ToArray();
Invoke:
object[] blah = soap.domainEdit("blah.com", results);
Unfortunately it doesn't look like the other end is able to process it:
System.InvalidOperationException: There was an error generating the XML document
. ---> System.InvalidOperationException: <>f__AnonymousType0`3[System.String,Sys
tem.String,System.String] cannot be serialized because it does not have a parame
terless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported()
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo sourc
e, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException
(Type type)
at System.Xml.Serialization.XmlSerializationWriter.GetPrimitiveTypeName(Type
type, Boolean throwIfUnknown)
at System.Xml.Serialization.XmlSerializationWriter.WriteArray(String name, St
ring ns, Object o, Type type)
at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElement(Str
ing name, String ns, Object o, Type ambientType)
at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElements()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterApi_Mo
del_SoapInterfaceService.Write31_domainEdit(Object[] p)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer61.Se
rialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Obje
ct o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Obje
ct o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Obje
ct o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientM
essage message)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodN
ame, Object[] parameters)
at **********.com.domain.mta1_ar1.Api_Model_SoapInterfaceService.d
omainEdit(String domain_name, Object[] params) in C:\Users\*****\Dropbox\C
ompsys\****\*****t\Web References\com.*****.mta1-ar1\
Reference.cs:line 226
at *****.Program.Main(String[] args) in C:\Users\*******\Dropbo
x\*****\******\******\Program.cs:line 107
I haven't worked with XML or soap calls much.
|
|
|
|
|
That absolutely is a dictionary. I'm surprised a dictionary doesn't generate the correct service XML ... have you tried passing the dictionary as the only argument to the service method?
|
|
|
|
|
The problem with that is the only parameter it wants is an object array (object[]).
So how do I convert a dictionary into an object[]? They are completely different types of arrays.
These methods were generated when I added the service to visual studio. Maybe I should try calling the service manually?
|
|
|
|