Hi
Is it possible to use a method as a parameter in C# or VB.NET?
static string s ()
{
return "s";
}
static void m (s m)
{
manupulateresultofmethods();
}
=======================
One applicaiton is to use Regex, as parameter
static void (regex m, regex s)
{}
So you can do input check, and the call to the method would fail, if the parameter regex match is false.
Do you get what I am saying? Is this possbile in C#?
-
-
-
Matthew van Eerde wrote:
Thanks for your reply.
What I am trying to do is simple. To validate imput at the method parameter level.
So suppose you have a new registration form. You want to validate input to guard aganst SQL injection.
instead of running it through a method. I just wish to give the method the input. If the parameter is correct, (match a regex parameter) then call method, else throw exception >> calling error
So void method (regex r, otherparameters)
the r would be accepted only if it match the regex expression. without need to write a method to validate the stuff.
If there is such capacity in C# , can you demonstrate a simple example, so as to help me understand?
Thanks again.
-
If you are just using regex to prevent SQL injection (ie stings like " ' or 1=1;-- " etc) then just use Parameterized queries which are already safe from sql injection attacks.
maybe im missing what you are getting at. -
PolymorphicCode wrote:Hi
Is it possible to use a method as a parameter in C# or VB.NET?
static string s ()
{
return "s";
}
static void m (s m)
{
manupulateresultofmethods();
}
=======================
One applicaiton is to use Regex, as parameter
static void (regex m, regex s)
{}
So you can do input check, and the call to the method would fail, if the parameter regex match is false.
Do you get what I am saying? Is this possbile in C#?
Would something like this work? Or are you trying to do something like new ThreadStart(method) or simply wanting a return Method()?
private string m {
set { name=value; }
get { return name; }
}
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.