Hi Sachin
You can't access the members of a property directly. Try saving myCLS.myStruct into a temporary variable, modifying it, then setting myCLS.myStruct to it.
Either that, or you could change the properties to return the STRUCT's fields, instead of the whole STRUCT.
Hope that helps
-Chris
--------------------
Thread-Topic: C# - Struct in a class.. can not access properties of the struct
thread-index: AcPkOdzeepjnEonlTke+XEEwEPD4gg==
X-Tomcat-NG: microsoft.public.dotnet.general
From: =?Utf-8?B?U0FDSElO?= <an*******@discussions.microsoft.com>
Subject: C# - Struct in a class.. can not access properties of the struct
Date: Mon, 26 Jan 2004 10:26:06 -0800
Lines: 60
Message-ID: <AF**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.general:122648
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.general
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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
}
public void test(){
CLS myCLS = new CLS();
///this statement is giving a compile time error:
///D:\ITSSjain\Visual Studio Projects\Bugreport\Class1.cs(26): Cannot modify the return value of 'Bugreport.CLS.myStruct' because it is not a variable.
myCLS.myStruct.Prop1 = "This is a test string";
}
}
/// <summary>
/// Test Structure
/// </summary>
public struct STRUCT{
public string Prop1;
public string Prop2;
}
/// <summary>
/// test class which has a public property exposing the above struct.
/// </summary>
public class CLS{
private STRUCT _myStruct;
public CLS(){
myStruct = new STRUCT();
}
public STRUCT myStruct{
get{
return _myStruct;
}
set{
_myStruct = value;
}
}
}
}
Why am I getting the Compile time error?
thanks
sachin jain
--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.