在Asp.Net编程中声明变量的最佳实践是什么? [英] What is the best practise of declaring the Variables in Asp.Net Programming?

查看:65
本文介绍了在Asp.Net编程中声明变量的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道在单独的类文件中声明变量或在相同的aspx.cs文件中声明.请告诉我声明变量的最佳实践.
在此先感谢

I just want to know the declaration of variables in a separate class file or declaring in the same aspx.cs file.Please any tell me the best practise of declaring the variables.
Thanks in advance

推荐答案

也可以使用部分类在逻辑上分离代码的各个部分.将所有输入控件包装到属性中非常有用.例如,对于每个TextBox控件,我创建一个字符串属性,并且只处理页面上的属性,而不处理诸如此类的语句:

Also you could use partial classes to separate parts of code logically. It''s very useful to wrap all input controls into properties. For instance, for every TextBox control I create string property and have a deal just with properties at the page but not with such statements like these:

Product product=new Product(); 
product.Name=tbxProductName.Text; 



就我而言,它看起来像:



In my case it''ll looks like:

product.Name=ProductName;

public string ProductName
{
   get{return tbxProduct.Text;}
   set{tbxProduct.Text=value;}
}



如果有帮助,请投票并接受答案.



Please vote and Accept Answer if it Helped.


也许 [<一个href ="http://www.dotnetspider.com/tutorials/BestPractices.aspx" target ="_ blank" title ="New Window"> ^ ]可以提供帮助.
Maybe this[^] can help.


这里是我的几个,

1.使用骆驼 [帕斯卡 [ ^ ]在声明变量的情况下,
2.请勿在类和大小写相同的情况下使用名称相同的变量.
3.在声明interface.
时,始终喜欢使用"I"后缀

如果有帮助,请 投票 接受答案 .
Here are few from me,

1. Use Camel[^] or Pascal[^] case while declaring variables,
2. Do not use variable having the same name with class and with same case.
3. Always prefer ''I'' suffix while declaring interface.


Please vote and Accept Answer if it Helped.


这篇关于在Asp.Net编程中声明变量的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆