doing some physics I stumbled over a problem. In a book of mine the moment of inertia of a Cylinder with the body axis through the center can be calculated with the formula in the picture. I tried to calculate this formula using the general term for the moment of inertia for a spinning object: I=(r^2)dm. But I could not find a way to define the mass (dm) of the cylinder in a way that would allow me to get to the formula in the picture.
I will appreciate any help!

We can use a theorem called Perpendicular Axis Theorem: The perpendicular axis theorem (or plane figure theorem) states that the moment of inertia of a planar lamina (i.e. 2-D body) about an axis perpendicular to the plane of the lamina is equal to the sum of the moments of inertia of the lamina about the two axes at right angles to each other, in its own plane intersecting each other at the point where the perpendicular axis passes through it.(From wiki)
It states that: $$I_{axis\space perpendicular\space to\space base\space of \space the \space cylinder} = I_{axis \space perpendicular \space to\space the\space side\space of \space cylinder } + I_{other \space axis \space perpebdicular \space to\space the\space side\space of \space cylinder } $$
We can also observe that $I_{axis \space perpendicular \space to\space the\space side\space of \space cylinder } = I_{other \space axis \space perpendicular \space to\space the\space side\space of \space cylinder }$ because spinning on either of the axis results in the same rotational motion. Coming to your question, we have to find $I_{axis \space perpendicular \space to\space the\space side\space of \space cylinder\space(center) }$ which is simply twice the Moment of Inertia along the axis perpendicular to the base of cylinder which we can easily calculate.
Moment of Inertia along the axis of the base of the circle(is same as the MoI of Cylinder along the axis of the base of cylinder using Stretch Rule is $\frac{1}{2}{M}{r^2}$
From here we can say $I_{center} = \frac{I_{base}}{2}$, and $dI_{center} = \frac{\frac{1}{2}dMr^2}{2} = \frac{dMr^2}{4}$
Since it's a solid cylinder I can also say $dM = \rho dV$ which is $dM = \frac{M}{\pi r^2l}\pi r^2 dl \implies dM = \frac{M}{L}dl$
Since we are moving some distance away from origin to form a cylinder, we can use the parallel axis theorem.
$$dI_{center} = dI_{base} + dI_{wherever\space I\space want}$$
$$dI_{center} = \frac{dMr^2}{4} + dMl^2$$
$$dI_{center} = \frac{Mr^2dl}{4L} + \frac{M}{L}l^2 dl $$
Since I'm moving from the origin, I try to move equally on both sides for the purpose of symmetry, meaning the limits when i integrate would be from $\frac{-L}{2} $ to $\frac{+L}{2} $ which gives me the full length of the cylinder $L$.
And I believe I can leave it as an exercise for the reader to evaluate the integral, which should turn out to be:
$$I_{center} = \frac{1}{4}Mr^2 + \frac{1}{12}Ml^2 $$