1

In this code i return the result from some operation in []x and []y. I read the data of them from text file:

double[] x = File.ReadAllLines(@"E:\TestFile.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray();
double[] y = File.ReadAllLines(@"E:\TestFile2.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray();
SimpleDTW dtw = new SimpleDTW(x, y);
dtw.computeDTW();
double result = new SimpleDTW(x, y).computeFForward();
Console.WriteLine("the paramter is " +result);

I want to find the name of two parameters that I call in the function.

For example: when I replace the two parameters x,y by z,y the input is the paramter is z,y

I want to return the name of parameter automatically. I want if we change paramters name print newest name automatically .

  • 2
    Do you want to print the `names` of the parameters, or the `values` of the parameters? You state you want the names, but I can't understand why you would want that. Furthermore, your code actually shows you are using the `result` of the function, so it's very unclear what you are actually asking for. Please can you **edit your question** to clarify? – RB. Feb 18 '14 at 10:29
  • i want to print the name of the parameters Because i want to tell me i make the opeartion for any two variables Because i have many operations – user3320101 Feb 18 '14 at 10:37
  • Nope i want if we change paramters name print newest name automatically – user3320101 Feb 18 '14 at 10:52
  • You cannot find the variable names, and the name of method parameters are constant values that you declare when you declare the method. So, which one do you want? What are you trying to achieve? What is the relevance of your variable names? – Mat J Feb 18 '14 at 10:54
  • I want to use variable name to tell me the operation between any two variable because i have group of variables and operations – user3320101 Feb 18 '14 at 11:09
  • In that case, You should group such variables into classes and create overloads for your `SimpleDTW`'s constructor which accept such different types of arguments and act accordingly. – Mat J Feb 18 '14 at 11:50
  • I find the soultion from Mathew thanks for help . – user3320101 Feb 18 '14 at 11:53
  • possible duplicate of [How can you get the names of method parameters?](http://stackoverflow.com/questions/214086/how-can-you-get-the-names-of-method-parameters) – RB. Feb 18 '14 at 13:29
  • @Mathew Actually, you can reflect on a method and find the parameter names. In fact, you can even reflect on a method and find it's internal variables, which is pretty cool! I've voted to close this question as a duplicate as this has been asked a few times. – RB. Feb 18 '14 at 13:30
  • @RB. I'm well aware of reflection method to get method parameter names, but I don't think it is possible with variable names.That's why I asked which one he need. Can you provide a reference regarding finding variable names if that is possible actually? – Mat J Feb 18 '14 at 14:20
  • @Mathew My mistake - you can [get the local variables of a method](http://msdn.microsoft.com/en-us/library/system.reflection.methodbody.localvariables(v=vs.110).aspx), but not their name (which is obvious in hindsight, as the MSIL doesn't contain it - you'd need to start digging around the PDB for that info). Apologies :) – RB. Feb 18 '14 at 14:24
  • Yes, I'm aware of that property. And no need of apologies :) – Mat J Feb 18 '14 at 15:13

2 Answers2

1

If you want to get the name of parameter you should use set and get method and you can save the name of the parameter or you can use dictionary in c# it's will help you .

MARK
  • 336
  • 1
  • 6
  • 23
0

Not sure I understand your problem.

I would add name parameter to your SimpleDTW,

String XName {get; set;}
String Yname {get; set;}

And a ToString() Method :

public String ToString(){
 return String.Format("The parameter is {0}: {1}, {2}:{3}",XName,X,YName,Y);
}
Clement Dungler
  • 737
  • 6
  • 10