Find the simplest counterexample against exchanging limit and summation

I would need a very simple counterexample to show that $$ \lim_{M\to\infty}\sum_{t=1}^M f(t,M) $$ may not necessarily be equal to $$ \sum_{t=1}^\infty \lim_{M\to\infty}f(t,M)\ . $$ The situation here is (slightly) different from the commonly asked question about interchanging limits and infinite summation, as $M$ is itself driving the upper limit of the sum. Can you exhibit a simple function $f$ which does the job? [Note that it should depend explicitly on $M$!]. I could only come up with an overly complicated situation, but I think I am missing something potentially very simple... Many thanks for you help.


Using Iverson brackets, $$ f(k,M)=[k=M] $$ $$ %f(k,M)=\left\{\begin{array}{} %0&\text{if }k\ne M\\ %1&\text{if }k=M %\end{array}\right. $$


Let $f(t,M) =\frac{t}{M}$, then

$\lim_{M\rightarrow \infty} \sum_{t=1}^{M} \frac{t}{M} = \infty$

as it is just the arithmetic series over M,

$\lim_{M \rightarrow \infty} \frac{M(M+1)}{2M} = \lim_{M\rightarrow \infty} \frac{M+1}{2}$

while

$\sum^\infty_{t=1} \lim_{M\rightarrow \infty} \frac{t}{M} = 0 $,

as every summand is zero for every finite $t$.


One example I can think of is: $f(t,M)=\frac1M g(\frac tM)$ where $g$ is continuous on $[0,1]$, so that $$\lim_{M\rightarrow \infty}\sum_{t=0}^{M}f(t,M)=\int_0^1 g(x)\,\mathrm{d}x$$ but $\sum_{t=0}^{\infty}\lim_{M\rightarrow \infty}f(t,M)=0$ if $g(0)\neq 0.$
For example you can choose $g(x)=x+1\text{ and }f(t,M)=\frac1M (1+\frac tM).$
EDIT: Of course that's a Riemann series, I thought I'd mention it.


Similar to @cgrudz's answer but a bit simpler. $$f(t,M)=1/M$$ Then $\lim_{M\to\infty}\sum_{t=1}^M1/M=1$ while $\sum_{t=1}^\infty\lim_{M\to\infty}1/M=0$.