Re: Basic info needed on struct in C#

From: Alex (alexware69_at_hotmail.com)
Date: 03/24/04


Date: Wed, 24 Mar 2004 14:09:56 -0500

Hi . What you are doing in your example is already done by the default
constructor, so you dont need to initialize all the members to zero.
Instead try changing to nonzero values.

regards, alex.

"Gets" <anonymous@discussions.microsoft.com> wrote in message
news:DA754FFC-A7F5-486C-9EDC-DB25D8E20DC1@microsoft.com...
> hi,
>
> i am beginner in C# i am currently working on Structures in C#
> i found the following stmt in MSDN for structures in C#
>
> It is an error to declare a default (parameterless) constructor for a
struct. A default constructor is always provided to initialize the struct
members to their default values.
>
> i was able o catch the first sentence of it. But the second sentence i am
not able to understand
> i tried with following example
> like
>
> public struct xxx
> {
> public int i,k;
> public xxx()
> {
> i=0; /* as per second sentence i feel this should excute but its
giving error */
> k=0;
> }
> }
>
>
> can anyone help me
>
> Thanks in advance
> Gets



Relevant Pages

  • Re: How to initialize a member struct
    ... I can't give this struct a constructor. ... class constructor (call it "TemplatedClass") in another DLL library. ... This leaves me with trying to come up with a way to initialize ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Initialization & Inheritance
    ... for a recent project I was trying to initialize members of a derived ... class from the constructor of the super class (done using an abstract ... private int foo = 0; ... Now I know how to get my intended behavior, just don't initialize foo = ...
    (comp.lang.java.programmer)
  • Re: remove structs default constructor?
    ... I can only initialize those private members via constructor ... if the default constructor does not disappear once I ... > create my own struct constructor, the caller can create a struct still ... Imagine only having proper values. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Initialization & Inheritance
    ... for a recent project I was trying to initialize members of a derived ... class from the constructor of the super class (done using an abstract ... initialize, but double initialization. ... if you used the pointer as it stood, ...
    (comp.lang.java.programmer)
  • Re: Structs cannot contain explicit parameterless constructors
    ... What do you use this type of struct for? ... have a default parameterless constructor. ... the C# compiler disallows definition ... I'm slightly perplexed that I can't explicitly initialize a ...
    (microsoft.public.dotnet.languages.csharp)