|
hi,
i'm designing an exception for my program and have the following problem. i want an additional constructor, which gets an int as paramter, builds a string out of it and calls the base-classes constructor with a string.
something like
class MyException : ApplicationExcpetion
{
...
public MyException(int errorCode)
{
string message;
switch(errorCode)
{
case
default: message="unkown errorcode"; break;
}
base(message);
}
}
but C# tells me: "Use of keyword base is not valid in this context"
i'm stuck. anyone any idea?
thx!
:wq
|
|
|
|
|
You can only call the base constructor like the following.
<br />
class MyException: ApplicationException<br />
{<br />
pubilc MyException(int errorcode) : base ( MyException.GetErrorString(errorcode) ) {<br />
}<br />
}<br />
The base constructor can only be called in that location.
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
yeah, with GetErrorString being a static function is does work - thanks a lot!
sometimes it's like a blocking in your head, when you're coding all day long...
:wq
|
|
|
|
|
I would also prefer to be able to delay the base construction. Look at my case.
class MyException: ApplicationException
{
int errorcode;
pubilc MyException() {
errorcode = GetErrorCode();
base ( MyException.GetErrorString(errorcode) );
}
}
Now I wouldnt have to call the GetErrorCode() function everytime when i need to throw it
Maybe there is a way to pre-initialise some variables...
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
Hi all,
Does anyone know how to determine which node of a treeview control the mouse pointer is over when a drop occurs? Maybe I am asking the wrong question: I want to allow the user to drag something from a listbox control onto a particular node of a tree view so that the dragged object can be added as a child node.
Any thoughts?
Thanks,
Bill
|
|
|
|
|
//Gets the point relative to the treeview
Point dragPoint = tv.PointToClient( new Point(e.X, e.Y) );
//Gets the treenode
TreeNode target = tv.GetNodeAt( dragPoint.X, dragPoint.Y );
|
|
|
|
|
It's always so simple once you know what the answer is.
Thanks.
|
|
|
|
|
I have 3 functions. All 3 the functions are identical except for a type and a function.
Now i want to combined all three into one. I assume it would be,
void CombinedFunction(Type type, SomeHandler function);
No the problem i have is, is that not all of the functions share the same parameters. All 3 have common parameters, but one has 2 extra parameters.
Would i HAVE to overload that function to pass any of the functions as a parameter.
Hope that makes sense
Thanx
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
O ya I solved this, noted though far down the optional parameter thread
The easier, better way was just to overload the function as the 2 optional parameters had fixed values when used in that context.
And...the function works beautifully
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I am using regex (regular expressions) in my C# application. I am pulling out the first name like this...
Regex regName = new Regex( @"(?<Last>\S+), (?<First>\S+)" );
Match pMatch = regName.Match( "Doe, John" );
Text strFirst = pMatch.Groups[ "First" ].Value;
Question: If the user changes the name to 'Jane', how can I use regular expressions to replace the first name?
If strFirst = "Jane", then I want a new string to be "Doe, Jane".
Thanks!!
|
|
|
|
|
You'll want to use Regex.Replace, and then create a replacement string. Something like:
Regex regName = new Regex( @"(?<last>S+), (?<first>S+)");
regName.Replace (string, @"\k<last>, Jane");
The \k refers to whatever matched the "Last" capture.
If you're playing with regex, you might like this utility:
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=regular%20expression%20workbench
|
|
|
|
|
Eric, there's a link tool down at the bottom. Very handy. Just highlight and click link[^]
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=regular%20expression%20workbench [^]
David Stone
But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*.
Shog9
|
|
|
|
|
Is it safe to assume that anytime you do some sort of COM Interop with a dll that wasn't written using the .NET Framework that the method call needs to be prefixed with the unsafe marker, or is this only needed when the method deals with pointers that are outside the bounds of .NET to handle directly?
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
unsafe int SomeFunction(....);
Nick Parker
|
|
|
|
|
U only have to specify unsafe if the compiler complains
No, but really unsafe only needs to be declared if you are using pointer notation in C# ( *, &, -> ). It is recommneded though (as far as I am aware) to use the Marshalling class as far as possible, else they wouldnt have called it "unsafe".
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
U only have to specify unsafe if the compiler complains
Somehow I believe more people than you think use this method.
Nick Parker
|
|
|
|
|
Is it possible to make a method to have options parameters, without defining the function for each valid configuration?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Not sure, however you could always overload the function.
Nick Parker
|
|
|
|
|
|
|
If you follow the C++ model, the default value is burned into your client-side code, and you can't update it without forcing the user to recompile.
We've talked a bit about whether you could have the compiler automatically generate the overloads that you would write yourself. Would that work for you?
|
|
|
|
|
|
That would be awesome! Get's my vote...tell Anders that.
David Stone
But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*.
Shog9
|
|
|
|
|
Eric Gunnerson (msft) wrote:
We've talked a bit about whether you could have the compiler automatically generate the overloads that you would write yourself. Would that work for you?
Yes!
You should definitely keep talking about that. This and the lack of (obvious) documentation around Attributes are my two biggest whines about C#/.NET.
There's little more irritating than having a function with 6 optional arguments and having to write 6 one-line overloads which in reality take up 30 lines and give you 6 more paths for testing.
Paul
|
|
|
|