Asp.net之 类和结构的区别
1、类是引用类型,结构则是值类型。因此结构是放在栈(Stack)里,类则仅仅是将引用地址存放在栈里,而具体的值则存放在堆(heap)里。
2、据第1点可以得出结论,那就是类对象通常用来传递大数据,而结构对象则用来传递小数据。
3、类可以继承和被继承,而结构则不支持。但结构和类一样可以继承自接口。
4、结构对象不能像类对象一样赋值为null。
5、结构没有析构器。类有构造和析构函数。
6、结构不能像类一样定义为抽象的。
7、在结构中不能重写方法,除非是object类型的如下方法:
Equals()
GetHashCode()
GetType()
ToString()
若要让结构具有多态特性,可以让其实现接口。
8、在类中定义的事件是线程安全的,而结构则不是。
9、结构总是具有一个默认的公共无参构造函数,但却不能像类一样定义私有的无参构造函数(结构也不能再定义公共的无参构造函数,这与类不相同)。
10、类中的静态构造函数会被调用,而结构却不能。因此在结构中定义的静态构造函数,虽然可以编译通过,但却没有价值。
11、结构不能像类一样定义volatile字段。volatile字段主要用于并发,它相当于方法体的lock。
12、可以对结构类型使用sizeof,对类则不行。
13、类的字段会被自动初始化为0/false/null,而结构则不能。
14、在结构中不能直接对字段初始化,而类则可以。
15、结构和类对于System.Object.Equals()方法的体现是不相同的。
==============Test 01=============
namespace ClassAndStruct
{
class Program
{
static void Main(string[] args)
{
StructTest st = new StructTest(3,4);
Console.WriteLine(st.GetSpace().ToString());//这里输出 12
}
}
public struct StructTest
{
public int length;
public int width;
//结构中不能有实例字段初始值设定项
//public int length=0;
//结构中不能有实例字段初始值设定项
//StructTest structTest = null;
//结构不能包含显式的无参数构造函数
//public StructTest()
//{ }
public StructTest(int a, int b)
{
length = a;
width = b;
}
public int GetSpace()
{
return length * width;
相关文档:
法一:调用winrar
using Microsoft.Win32;
using System.Diagnostics;
protected void Button1_Click(object sender, EventArgs e)
{
RAR(@"E:\95413594531\GIS", "tmptest", @"E:\95413594531\");
}
/// < ......
Introduction
In this article, we will take a closer look at how ASP.NET pages post back to themselves, and how to customize this feature in our web applications.
function __doPostBack(eventTarget, eventArgument)
One of the most important features of the ASP.NET environment is the ability to decla ......
using System;
using System.IO;
using System.Web;
namespace SEC
{
/**////
/// 对文件和文件夹的操作类
///
public class FileControl
{
public FileControl()
{
}
/**////
/// 在根目录下创建文件夹
///
///
要创建的文件路径
public void CreateFolder(string FolderPathName)
{ ......
public class PageBase:System.Web.UI.Page
{
public PageBase()
{
//
// TODO: Add constructor logic here
//
}
protected override void InitializeCulture()
{
// ......