为了使我的代码更加清晰,我尝试做类似的事情:
var result = $@"...
<div class='modal-body'>
{content}
</div>
{(haveButtons ? "" : "<div class='modal-footer'>")}
{modalButtons.ForEach(m => "INSERT SOME HTML")}
{(haveButtons ? "" : "</div>")}
..."
但是,当然,这不会编译,因为在lambda中我需要放置一些代码而不仅仅是魔法返回。有没有办法做到这一点?
答案 0 :(得分:2)
{string.Join("", modalButtons.Select(m => "INSERT SOME HTML"))}