G
Guest
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
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