Typically you need a Hold Attribute on your Test function and to pass the "symbol" unevaluated:
a[1] = 2.1; a[2] = 3.5;
SetAttributes[Test, HoldFirst]
Test[x : _[n_]] := Block[{i}, i = n; {i, x}] (* Block is superfluous here *)
Test[a[1]]
Test[a[2]]
{1, 2.1}
{2, 3.5}
This will not let you do something like Test /@ {a[1], a[2]} however as e.g. a[1] will first evaluate to 2.1 and there is nothing to match.
If you cannot pass the argument unevaluated you have a bit of a problem. I strongly suggest you rethink the design of your program in that case. However in an effort to be helpful you could attempt a reverse look-up in the DownValues of a, assuming you somehow "know" the Symbol name a.
test2[v_, s_Symbol] :=
Cases[DownValues[s], (_[s[n_]] :> v) :> {n, v}]
test2[#, a] & /@ {2.1, 3.5}
{{{1, 2.1}}, {{2, 3.5}}}
fn[a[n_]] := Row@{"this one is ", n}. Somehow I think that you might mean something else however. Perhaps you are having evaluation problems, e.g. there is an existing definition likea[1] = 3.2? – Mr.Wizard Aug 01 '16 at 00:10a[1]ora[2]? If soSetAttributes[Test, HoldAll]; Test[a[i_]] := iwould work. But it won't work in all applications. E.g.var = a[2]; Test[var]. – Michael E2 Aug 01 '16 at 00:29{i, a[i]}is shorter thanTest[a[i]]. – Michael E2 Aug 01 '16 at 00:58aand the index (1or2) separate to begin with. In fact this is one of the major advantages of using "indexed objects" like this, e.g. (32202). You might define yourTestfunction something likeTest[s_Symbol, i_] := {i, s[i]}then call it withTest[a, 1]. This does not require any Hold attributes. – Mr.Wizard Aug 01 '16 at 01:21test[s_Symbol][i_] := {i, s[i]}which would allowtest[a] /@ {1, 2}. Finally please consider not starting user function names with capital letters as there is risk of collision with built-ins, either now or in a future version. – Mr.Wizard Aug 01 '16 at 01:24