为什么在C#中使用.cs文件 [英] why is .cs file used in C#

查看:378
本文介绍了为什么在C#中使用.cs文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么在asp.net的C#中使用.cs文件,以及此abc.cs文件的基本用途是什么.

i wana know why .cs file is used in C# in asp.net and what is the basic purpose of this abc.cs file.

推荐答案

The. cs文件是每个类的文件后面的代码.
代码隐藏文件是使用任何Microsoft .NET运行时兼容语言编写的预编译模块文件.

这些是已编译并存储在服务器上的dll(主要在应用代码目录中).

文件背后的代码不过是部分类而已,它是在.Net 2.0中引入的.
要了解有关后台代码与内联代码的更多信息,请查看后台代码与内联代码 [ ^ ].
The .cs file is the code behind file for every class.
Code-behind files are files that are pre-compiled modules written in any of the Microsoft .NET runtime compliant languages.

These are the dll that are compiled and stored on the server (mostly in the app-code directory).

The code behind file is nothing but a partial class and was introduced in .Net 2.0.
To read more about code behind versus code inline have a look at Code Behind vs. Code Inline[^].


我们将只在cs文件中编写逻辑代码...
扩展名是.cs ..
we will write logic code in cs file only...
the extension is .cs..


基本上,您会在asp.net应用程序中找到两种类型的CS文件.一个是* .aspx.cs,另一个是* .cs

第一个用作* .aspx文件的文件后面代码.例如,在任何应用程序中找到的最常见文件是default.aspx和default.aspx.cs

Default.aspx文件包含要向用户显示的所有UI(HTML),而Default.aspx.cs文件包含用于处理aspx文件中的内容的代码.您可以在aspx文件中有一个Label控件以显示已登录的用户名,并且您将在aspx.cs文件中编写代码以在该Label控件中设置已登录的用户名.

* .cs文件主要是由开发人员创建的类文件,用于为该功能编写额外的逻辑.例如,您可以创建一个helper.cs类并编写代码以返回登录用户的名称.然后,您可以从default.aspx.cs文件调用此函数以显示登录的用户名.在这种情况下,创建类文件的好处是可以在任何页面上重复使用它,即可以通过从aspx.cs文件中调用该类函数在任何aspx页面上显示登录的用户名.

通常,将aspx文件添加到项目中会自动添加一个aspx.cs文件.对于* .cs文件,您需要首先选择additem,然后从文件类型列表中选择类文件.
Basically you will find two types of cs files in a asp.net application. One is *.aspx.cs and another is *.cs

The first one works as code behind file for a *.aspx file. For instance, the most common file you find in any application is default.aspx & default.aspx.cs

Default.aspx file contains all the UI (HTML) which you want to show the user and Default.aspx.cs file contains code to manipulate the content in the aspx file. You can have a Label control in aspx file to display logged in user name & you will write code in aspx.cs file to set the logged in user name in that Label control.

*.cs files are mainly class files created by developers to write extra logic for the functionality. For example, you can create a helper.cs class and write code for return the name of the logged in user. You can then call this function from the default.aspx.cs file to display the logged in user name. The benefit of creating the class file in this case is that it can be reused on any page, i.e. you can display the logged in user name in any aspx page by calling this class function from the aspx.cs file.

Generally adding an aspx file to the project adds an aspx.cs file automatically. For *.cs file, you will need to first select additem and then select class file from the list of file types.


这篇关于为什么在C#中使用.cs文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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