我如何创建一个类 [英] How I Create A Class
问题描述
嗨
我想为fileuploader代码创建一个类,并在该类中传递一个变量或参数我该怎么做请帮帮我
这里代码
Hi
I want to create a class for fileuploader code and pass a variable or parameter in that class How i do that Please help me
Here the Code
if (FileUpload1.HasFile)
{
byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
FileUpload1.PostedFile.InputStream.Read(img, 0, FileUpload1.PostedFile.ContentLength);
string file_ext = "" + FileUpload1.PostedFile.FileName;
string ext = Path.GetExtension(file_ext);
Response.Write(FileUpload1.PostedFile.ContentLength);
if ((ext.ToLower() == ".txt") || (ext.ToLower() == ".docx"))
{
File.WriteAllBytes(Server.MapPath("~/" + file_ext), img);
}
我怎么样创建一个类,此代码的方法。
how i create a class , Method for this Code .
推荐答案
您将在ASP.NET中创建类,就像在.NET框架中创建类一样;或者我应该用其他语言说。像这样,
You will create the class in ASP.NET, just the way you create a class in .NET framework; or should I say in other languages. Like this,
public class MyClass {
// members here..
}
然后在函数内部可以传递值,或者通过覆盖变量来填充成员。例如,如果你有一个变量来保存文件名,例如,
Then inside the functions you can pass the values, or populate the members by overriding the variables. For example, if you're having a variable to hold the file name such as,
public class MyClass {
// static member
public static string FileName { get; set; }
}
您将把它传递给,
You will pass it as,
MyClass.FileName = "file-name.png";
等等...此外,最好还是阅读 MSDN文档指南 [ ^ ]。 ASP.NET允许您使用C#和VB.NET开发Web应用程序,因此您可以阅读有关其中任何文档的文档并了解核心概念。
And so on... Furthermore, it would be better to read this MSDN documentation guide[^] about Classes in C#. ASP.NET allows you to develop web applications in C# and VB.NET, so you can read documentations about any of them and learn about core concepts.
这篇关于我如何创建一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!