how to create function inside another function in c#,is it possible?
It is most certainly possible.
You can create delegates, which are functions, inside other methods. This works in C# 2.0:
public void OuterMethod() {
someControl.SomeEvent += delegate(int p1, string p2) {
// this code is inside an anonymous delegate
}
}
And this works in newer versions with lambdas:
public void OuterMethod() {
Func<int, string, string> myFunc = (int p1, string p2) => p2.Substring(p1)
}
Eilon's answer is technically correct in that you can use delegates to effectively create a method within a method. The question I would ask is why you need to create the function in-line at all?
It's a bit of a code smell to me. Yes, the internal method is reusable to the rest of your method, but it suggests that there is an element of the code where the design hasn't really been thought through. Chances are, if you need to use a delegate in this way, you would likely to be doing something fairly small and repetitive that would be better served as a function in the class, or even in a utility class. If you are using .Net 3.5 then defining extensions may also be a useful alternative depending on the usefulness of the code being delegated.
It would be easier to answer this question better if you could help us to understand why you feel the need to write your code in this way.