473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

About Struct in CSharp


I have two questions about Structure in CSharp:

1. Why we can not override the Default Constructor in Structure.

2. Why we can not initialize the Fields in Structure.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
2 3267
There are some interop situations where the runtime could not guarantee that
such a constructor would be run, and therefore the language prohibits you
from writing one.

Initializing fields is the same issue, as it is done as part of the
constructor.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Jamil Ahmed" <na********@yahoo.com> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...

I have two questions about Structure in CSharp:

1. Why we can not override the Default Constructor in Structure.

2. Why we can not initialize the Fields in Structure.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2
structs are handled differently than classes in C#. The runtime will
automatically create default constructors that initialize your fields
to zero, false or null. This allows for quicker allocation of structs,
then classes. If you need default constructors or initializers, then
use a class.

Randy
http://www.kbcafe.com

Jamil Ahmed <na********@yahoo.com> wrote in message news:<uN**************@TK2MSFTNGP11.phx.gbl>...
I have two questions about Structure in CSharp:

1. Why we can not override the Default Constructor in Structure.

2. Why we can not initialize the Fields in Structure.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SACHIN | last post by:
I have this class as part of a Consol application. using System; namespace Bugreport { /// <summary> /// This class tries to use the Class/Struct combination. /// </summary> class Class1 {
3
by: Matteo Cima | last post by:
hi! i have a struct like: Public struct conf { public bool debug=false; public int opPalm=-1; public int neMess=0; public bool caPart = false; }
17
by: Archer | last post by:
I defined my class as: class List { public List Next; public int Data; public List() { Data=0; } }
26
by: phoenix | last post by:
Hello, I've got a design question. I need to keep track of some variables and I am planning to put them inside a class or struct. Basically I'm talking about 10 bools, 20 ints and 2 arrays of...
5
by: Chua Wen Ching | last post by:
Hi there, I am very curious on this code: // declared as structure public struct Overlapped { public IntPtr intrnal; public IntPtr internalHigh;
10
by: Ashish Sheth | last post by:
Hi Gurus, In C# why struct can't be inherited from another struct, just like a class can be inherited from another class? another question is all struct by default are inherited from System.Object...
1
by: ari | last post by:
hi all, How to translate such struct to csharp codes? typedef struct{ char *FileName; HANDLE gHandle; char cbDir; WORD wAddress; DWORD* FileCount; int FileFlag;
37
by: JohnGoogle | last post by:
Hi, Newbie question... After a recent article in VSJ I had a go at implementing a Fraction class to aid my understanding of operator overloading. After a previous message someone suggested...
3
by: Ashutosh | last post by:
Hello, I am a newbie in CSharp. In C++ if we want to read from socket into the struct object we directly type cast it as recv(socketid,(char*),&struct_object,sizeof(struct object)) But C...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.