alreadyused
Regular
- Joined
- Jan 13, 2006
- Messages
- 69
I am trying to learn more c# and I'm having an issue. I managed to get it to work but I want to know if there's a better way.
I have an interface in a common namespace, and a class that uses that in an application namespace.
I have overloaded a function to receive a string, integer or double, and defined that in the interface.
I'm storing it in XML and don't care about the variable type, so I want to save it as a string each time. I have to build up the xPath a bit, based on class vars, so ideally I want to call the setVal(string, string) function from the others.
But, I'm not able to say this.setVal because it claims that my class doesn't have that function.
Below is the only way I have been able to get it to work. Is there a better way?
so is that the best way of doing it? and if so, is there a term for this? sorry if that's a total noob question, I browsed around here and google and can't find anything on it.
I have an interface in a common namespace, and a class that uses that in an application namespace.
I have overloaded a function to receive a string, integer or double, and defined that in the interface.
I'm storing it in XML and don't care about the variable type, so I want to save it as a string each time. I have to build up the xPath a bit, based on class vars, so ideally I want to call the setVal(string, string) function from the others.
But, I'm not able to say this.setVal because it claims that my class doesn't have that function.
Below is the only way I have been able to get it to work. Is there a better way?
C#:
namespace company.project.common{
interface MyInterface{
void setVal(string,string);
void setVal(string,integer);
void setVal(string,double);
}
}
// -------------------
uses company.project.common;
namespace company.project.mainapp{
public class MyObject : MyInterface{
void MyInterface.setVal(string key, string value){
string xPath;
// code to build xPath, verify the XmlNode exists, etc goes here but is omitted
} // str,str
// this works, but not sure how efficient?
void MyInterface.setVal(string key, int value){
MyInterface b = this;
b.setVal(key, value.ToString());
} // str,int
// this does not work, but does in VB
void MyInterface.setVal(string key, double value){
this.setVal(key, value.ToString());
} // str,2x
}
}
so is that the best way of doing it? and if so, is there a term for this? sorry if that's a total noob question, I browsed around here and google and can't find anything on it.
Last edited by a moderator: