申报inline- code类在ASPX / C# [英] Declare a class in inline-code in aspx/c#
本文介绍了申报inline- code类在ASPX / C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含 ASPX
脚本一个自认为现在需要一个小班的一个功能。有什么办法来声明在本页面code类不添加code的后面( aspx.cs
)文件?
I've got a self contained aspx
script that now needs a small class for one function. Is there any way to declare a class in the code of this page without adding a code behind (aspx.cs
) file?
我希望把一切都在一个单一的文件整洁的缘故。
I'd like to keep everything in one single file for neatness sake.
推荐答案
我希望把一切都在一个单一的文件整洁的缘故。
我看不出混合code和标记可能永远不会整齐。话虽这么说,你可以添加的内部类<脚本>
块,例如: -
I'd like to keep everything in one single file for neatness sake.
I fail to see how mixing code and markup could ever be neat. That being said, you could add the class inside of a <script>
block, e.g: -
<script runat="server">
public class MyClass
{
public static string Example()
{
Response.Write("Hello world");
}
}
</script>
这篇关于申报inline- code类在ASPX / C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文