private struct MySTRUCT
{
public IntPtr hwndMyObj;
public Int32 idMyObj;
public Int32 MyCode;
}
In Vb.Net 2005 code above, I am getting a warning message
"MyProj.MyClass.MySTRUCT.hwndMyObj is never assigned to,and will always have
its default value."

The same message for idMyObj and MyCode. How do I resolve it?

RE: Field is never assigned to, and will always have its default value by Shayaan

Shayaan
Wed Sep 20 08:59:47 CDT 2006

My apology; it is C# 2005 code.

"Shayaan" wrote:

> private struct MySTRUCT
> {
> public IntPtr hwndMyObj;
> public Int32 idMyObj;
> public Int32 MyCode;
> }
> In Vb.Net 2005 code above, I am getting a warning message
> "MyProj.MyClass.MySTRUCT.hwndMyObj is never assigned to,and will always have
> its default value."
>
> The same message for idMyObj and MyCode. How do I resolve it?

Re: Field is never assigned to, and will always have its default value by Stoitcho

Stoitcho
Wed Sep 20 10:03:37 CDT 2006

Shayaan,

That is because you are using public fileds. the comiler always complains
about public or internal unasigned fileds.

Wrap them in properties; it will make the compiler happy.


struct MySTRUCT
{
private IntPtr hwndMyObj;
private Int32 myCode;
private Int32 idMyObj;

public IntPtr HwndMyObj
{
get { return hwndMyObj; }
set { hwndMyObj = value; }
}

public Int32 IdMyObj
{
get { return idMyObj; }
set { idMyObj = value; }
}

public Int32 MyCode
{
get { return myCode; }
set { myCode = value; }
}

}


--
HTH
Stoitcho Goutsev (100)

"Shayaan" <Shayaan@discussions.microsoft.com> wrote in message
news:352BC33E-05DD-4890-B0C9-606410F8A2D3@microsoft.com...
> My apology; it is C# 2005 code.
>
> "Shayaan" wrote:
>
>> private struct MySTRUCT
>> {
>> public IntPtr hwndMyObj;
>> public Int32 idMyObj;
>> public Int32 MyCode;
>> }
>> In Vb.Net 2005 code above, I am getting a warning message
>> "MyProj.MyClass.MySTRUCT.hwndMyObj is never assigned to,and will always
>> have
>> its default value."
>>
>> The same message for idMyObj and MyCode. How do I resolve it?



Re: Field is never assigned to, and will always have its default v by Shayaan

Shayaan
Wed Sep 20 10:39:01 CDT 2006

Stoitcho,
Now I get the following errors on lines marked with 1, 2 and 3

1. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
'HwndMyObj'
2. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
'IdMyObj'
3. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
'MyCode'

struct MySTRUCT
{
private IntPtr hwndMyObj;
private Int32 myCode;
private Int32 idMyObj;

1. public IntPtr HwndMyObj
{
get { return hwndMyObj; }
set { hwndMyObj = value; }
}

2. public Int32 IdMyObj
{
get { return idMyObj; }
set { idMyObj = value; }
}

3. public Int32 MyCode
{
get { return myCode; }
set { myCode = value; }
}

}


"Stoitcho Goutsev (100)" wrote:

> Shayaan,
>
> That is because you are using public fileds. the comiler always complains
> about public or internal unasigned fileds.
>
> Wrap them in properties; it will make the compiler happy.
>
>
> struct MySTRUCT
> {
> private IntPtr hwndMyObj;
> private Int32 myCode;
> private Int32 idMyObj;
>
> public IntPtr HwndMyObj
> {
> get { return hwndMyObj; }
> set { hwndMyObj = value; }
> }
>
> public Int32 IdMyObj
> {
> get { return idMyObj; }
> set { idMyObj = value; }
> }
>
> public Int32 MyCode
> {
> get { return myCode; }
> set { myCode = value; }
> }
>
> }
>
>
> --
> HTH
> Stoitcho Goutsev (100)
>
> "Shayaan" <Shayaan@discussions.microsoft.com> wrote in message
> news:352BC33E-05DD-4890-B0C9-606410F8A2D3@microsoft.com...
> > My apology; it is C# 2005 code.
> >
> > "Shayaan" wrote:
> >
> >> private struct MySTRUCT
> >> {
> >> public IntPtr hwndMyObj;
> >> public Int32 idMyObj;
> >> public Int32 MyCode;
> >> }
> >> In Vb.Net 2005 code above, I am getting a warning message
> >> "MyProj.MyClass.MySTRUCT.hwndMyObj is never assigned to,and will always
> >> have
> >> its default value."
> >>
> >> The same message for idMyObj and MyCode. How do I resolve it?
>
>
>

Re: Field is never assigned to, and will always have its default v by Christof

Christof
Thu Sep 21 01:59:17 CDT 2006

The code compiles fine on my machine (though i had to add using System;

from the error messages i suppose that you defined
private IntPtr HwndMyObj;
instead of
private IntPtr hwndMyObj;

look at the capital vs. small 'h' in th identifier.

convention is:
public properties beginn with capital letters.
private fields begin with small letters.

"Shayaan" <Shayaan@discussions.microsoft.com> schrieb im Newsbeitrag
news:A2BFB9D4-A319-4C93-BD38-CAC1265D71C4@microsoft.com...
> Stoitcho,
> Now I get the following errors on lines marked with 1, 2 and 3
>
> 1. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
> 'HwndMyObj'
> 2. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
> 'IdMyObj'
> 3. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
> 'MyCode'
>
> struct MySTRUCT
> {
> private IntPtr hwndMyObj;
> private Int32 myCode;
> private Int32 idMyObj;
>
> 1. public IntPtr HwndMyObj
> {
> get { return hwndMyObj; }
> set { hwndMyObj = value; }
> }
>
> 2. public Int32 IdMyObj
> {
> get { return idMyObj; }
> set { idMyObj = value; }
> }
>
> 3. public Int32 MyCode
> {
> get { return myCode; }
> set { myCode = value; }
> }
>
> }
>
>
> "Stoitcho Goutsev (100)" wrote:
>
>> Shayaan,
>>
>> That is because you are using public fileds. the comiler always complains
>> about public or internal unasigned fileds.
>>
>> Wrap them in properties; it will make the compiler happy.
>>
>>
>> struct MySTRUCT
>> {
>> private IntPtr hwndMyObj;
>> private Int32 myCode;
>> private Int32 idMyObj;
>>
>> public IntPtr HwndMyObj
>> {
>> get { return hwndMyObj; }
>> set { hwndMyObj = value; }
>> }
>>
>> public Int32 IdMyObj
>> {
>> get { return idMyObj; }
>> set { idMyObj = value; }
>> }
>>
>> public Int32 MyCode
>> {
>> get { return myCode; }
>> set { myCode = value; }
>> }
>>
>> }
>>
>>
>> --
>> HTH
>> Stoitcho Goutsev (100)
>>
>> "Shayaan" <Shayaan@discussions.microsoft.com> wrote in message
>> news:352BC33E-05DD-4890-B0C9-606410F8A2D3@microsoft.com...
>> > My apology; it is C# 2005 code.
>> >
>> > "Shayaan" wrote:
>> >
>> >> private struct MySTRUCT
>> >> {
>> >> public IntPtr hwndMyObj;
>> >> public Int32 idMyObj;
>> >> public Int32 MyCode;
>> >> }
>> >> In Vb.Net 2005 code above, I am getting a warning message
>> >> "MyProj.MyClass.MySTRUCT.hwndMyObj is never assigned to,and will
>> >> always
>> >> have
>> >> its default value."
>> >>
>> >> The same message for idMyObj and MyCode. How do I resolve it?
>>
>>
>>



Re: Field is never assigned to, and will always have its default v by Stoitcho

Stoitcho
Thu Sep 21 08:48:34 CDT 2006

Shayaan,

Make sure that the property names and their backup fields have different
name. In my example the fileds start with small letters and the properties
with capitals.


--
HTH
Stoitcho Goutsev (100)

"Shayaan" <Shayaan@discussions.microsoft.com> wrote in message
news:A2BFB9D4-A319-4C93-BD38-CAC1265D71C4@microsoft.com...
> Stoitcho,
> Now I get the following errors on lines marked with 1, 2 and 3
>
> 1. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
> 'HwndMyObj'
> 2. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
> 'IdMyObj'
> 3. The type 'MyProj.MyClass.MySTRUCT' already contains a definition for
> 'MyCode'
>
> struct MySTRUCT
> {
> private IntPtr hwndMyObj;
> private Int32 myCode;
> private Int32 idMyObj;
>
> 1. public IntPtr HwndMyObj
> {
> get { return hwndMyObj; }
> set { hwndMyObj = value; }
> }
>
> 2. public Int32 IdMyObj
> {
> get { return idMyObj; }
> set { idMyObj = value; }
> }
>
> 3. public Int32 MyCode
> {
> get { return myCode; }
> set { myCode = value; }
> }
>
> }
>
>
> "Stoitcho Goutsev (100)" wrote:
>
>> Shayaan,
>>
>> That is because you are using public fileds. the comiler always complains
>> about public or internal unasigned fileds.
>>
>> Wrap them in properties; it will make the compiler happy.
>>
>>
>> struct MySTRUCT
>> {
>> private IntPtr hwndMyObj;
>> private Int32 myCode;
>> private Int32 idMyObj;
>>
>> public IntPtr HwndMyObj
>> {
>> get { return hwndMyObj; }
>> set { hwndMyObj = value; }
>> }
>>
>> public Int32 IdMyObj
>> {
>> get { return idMyObj; }
>> set { idMyObj = value; }
>> }
>>
>> public Int32 MyCode
>> {
>> get { return myCode; }
>> set { myCode = value; }
>> }
>>
>> }
>>
>>
>> --
>> HTH
>> Stoitcho Goutsev (100)
>>
>> "Shayaan" <Shayaan@discussions.microsoft.com> wrote in message
>> news:352BC33E-05DD-4890-B0C9-606410F8A2D3@microsoft.com...
>> > My apology; it is C# 2005 code.
>> >
>> > "Shayaan" wrote:
>> >
>> >> private struct MySTRUCT
>> >> {
>> >> public IntPtr hwndMyObj;
>> >> public Int32 idMyObj;
>> >> public Int32 MyCode;
>> >> }
>> >> In Vb.Net 2005 code above, I am getting a warning message
>> >> "MyProj.MyClass.MySTRUCT.hwndMyObj is never assigned to,and will
>> >> always
>> >> have
>> >> its default value."
>> >>
>> >> The same message for idMyObj and MyCode. How do I resolve it?
>>
>>
>>