In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the difference between C# class and structure". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the difference between C# class and structure"!
Can the sealed class of basic knowledge of C # have virtual functions?
Yes, the virtual function in the base class will be implicitly transformed into a non-virtual function, but the sealed class itself cannot add a new virtual function.
Example:
Class BaseClass {public virtual void F () {Console.WriteLine ("BaseClass.F");} sealed class DeriveClass: the virtual function F in the BaseClass {/ / base class is implicitly converted to a non-virtual function / / the new virtual function G public virtual void G () {Console.WriteLine ("DeriveClass.G");}} cannot be declared in the sealed class.
Basic knowledge of C # if there is only one property accessor for a virtual property in the base class, how many property accessors can there be after the inherited class overrides the property? What if there are get and set in the base class?
If there is only one property accessor for a virtual property in the base class, then there should be only one property overridden by the inherited class. If there are two property accessors, get and set, in the base class, there can be only one or two property accessors in the inherited class.
Can abstract of basic knowledge of C # be used with virtual? Can I use it with override?
The abstract modifier cannot be used with the static, virtual, and override modifiers
Which members can be included in the basic knowledge interface of C #?
Interfaces can contain properties, methods, index indicators, and events, but cannot contain constants, fields, operators, constructors, and destructors, and cannot contain any static members
What is the difference between basic knowledge and structure of C #?
Class: the class is the reference type assigned on the heap, and the instance of the class only copies the reference, pointing to the memory allocated by the same actual object. The class has constructors and destructors, and the class can inherit and be inherited.
Structure: the structure is the value type assigned on the stack (although the access speed of the stack is faster than the stack, but the resources of the stack are limited), the assignment of the structure will result in a new object. Structure has no constructor, but can be added. A structure has no destructor, and a structure cannot inherit from another structure or be inherited, but it can inherit from an interface just like a class.
Example:
From the above comparison, we can get some lightweight object usage structures, but large amounts of data or complex processing logic objects * use classes. For example, Geoemtry (an introduction in GIS, defined in the OGC standard) * uses classes, while members of Geometry midpoints * use structures.
Using System
Using System.Collections.Generic
Using System.Text
Namespace Example16 {
Interface IPoint {
Double X {
Get;set
}
Double Y {
Get;set
} double Z {
Get;set
}
/ / the structure can also inherit struct Point: IPoint {from the interface
Private double x, y, z
/ / structure can also add constructors
Public Point (double X, double Y, double Z) {
This.x = Xterthis.y = Yintthis.z = Z
}
Public double X {get {return x
}
Set {x = value
}
}
Public double Y {
Get {return x
}
Set {x = value
}
}
Public double Z {
Get {return x
}
Set {x = value
}
}
/ / the design of point Geometry is simplified here, and Project (coordinate transformation) is also included in the actual product.
Complex operations such as class PointGeometry {
Private Point value
Public PointGeometry (double X, double Y, double Z) {
Value = new Point (X, Y, Z)
}
Public PointGeometry (Point value) {
/ / the assignment of the structure allocates new memory this.value = value
}
Public double X {get {return value.X
}
Set {
This.value.X = value
}
}
Public double Y {get {return value.Y
}
Set {this.value.Y = value
}
}
Public double Z {get {return value.Z
} set {this.value.Z = value
}
}
Public static PointGeometry operator + (PointGeometry Left, PointGeometry Rigth) {
Return new PointGeometry (Left.X + Rigth.X, Left.Y + Rigth.Y, Left.Z + Rigth.Z)
}
Public override string ToString () {
Return string.Format ("X: {0}, Y: {1}, Z: {2}", value.X, value.Y, value.Z)
}
Class Program {
Static void Main (string [] args) {
Point tmpPoint = new Point (1,2,3)
PointGeometry tmpPG1 = new PointGeometry (tmpPoint)
PointGeometry tmpPG2 = new PointGeometry (tmpPoint)
TmpPG2.X = 4ntmpPG2.Y = 5ntmpPG2.Z = 6
/ / because the structure is a value type, the coordinates of tmpPG1 and tmpPG2 are not the same Console.WriteLine (tmpPG1)
Console.WriteLine (tmpPG2)
/ / because the class is a reference type, the modification of tmpPG1 coordinates affects tmpPG3 PointGeometry tmpPG3 = tmpPG1
TmpPG1.X = 7
TmpPG1.Y = 8
TmpPG1.Z = 9
Console.WriteLine (tmpPG1)
Console.WriteLine (tmpPG3)
Console.ReadLine ()
}
At this point, I believe you have a deeper understanding of "what is the difference between C# class and structure". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.