A recommended solution by me. We can abuse showexpl package, that is for rendering TeX code and its output side by side, by specify the graphic option to prevent the \LTXexample or \LTXinputExample from rendering the code.
The following code speaks my idea clearly. Some settings are left intact for you to make the rendered code look beautiful.
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{Program.cs}
using System;
namespace Delegate
{
class Program
{
// start
static void Main(string[] args)
{
for (int x = 0; x < 10; x++)
Console.WriteLine(x);
}
// stop
}
}
\end{filecontents*}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
\usepackage{xcolor}
\usepackage{showexpl}
\lstdefinestyle{Common}
{
language={[Sharp]C},
numbers=left,
numbersep=1em,
numberstyle=\tiny\noaccsupp,
frame=single,
framesep=\fboxsep,
framerule=\fboxrule,
rulecolor=\color{red},
xleftmargin=\dimexpr\fboxsep+\fboxrule,
xrightmargin=\dimexpr\fboxsep+\fboxrule,
breaklines=true,
breakindent=0pt,
tabsize=2,
columns=flexible,
includerangemarker=false,
rangeprefix=//\ ,
}
\lstdefinestyle{A}
{
style=Common,
backgroundcolor=\color{yellow!10},
basicstyle=\scriptsize\ttfamily,
keywordstyle=\color{blue}\bf,
identifierstyle=\color{black},
stringstyle=\color{red},
commentstyle=\color{green}
}
\usepackage{graphicx}
\begin{document}
\LTXinputExample[style=A,graphic=example-image-a]{Program.cs}
\end{document}

\begin/\end{figure}; second: put%after the first\end{minipage}; third: use thecapt-ofpackage and usecaptionof{figure}{Figure one.}– wasteofspace Jan 22 '14 at 14:10