i am trying to assign one object to other object but it is assigning and showing me this error can any one help me...?
Error1Cannot implicitly convert type 'DMLOperationOnArray.Test2' to 'DMLOperationOnArray.Test'D:\c# Prectice\DMLOperationOnArray\DMLOperationOnArray\Program.cs7017DMLOperationOnArray
using System;
namespace DMLOperationOnArray
{
class Program
{
static void Main(string[] args)
{
Test t = new Test();
t.Testmethod();
Console.Write("\n\n\n");
Test2 t2 = new Test2();
t2.Testmethod2();
t = t2; // error occured here
Console.ReadKey();
}
}
class Test
{
public void Testmethod()
{
int value = 20;
Console.WriteLine(value);
}
}
class Test2
{
public void Testmethod2()
{
int value = 40;
Console.WriteLine(value);
}
}
}

VulpesPosted Jun 17, 2011, 4:07 AM
A cast won't work either as there is no relationship between Test and Test2.
However, if Test2 were to inherit from Test, then it would work as it stands:
Mamta MPosted Jun 17, 2011, 4:47 AM
You are right. I had assumed they were related, when in fact they weren't. Thanks for pointing that out.
-Mamta
Mamta MPosted Jun 17, 2011, 3:22 AM
t= (Test) t2;
Ish BandhuPosted Jun 17, 2011, 2:51 AM
{
static void Main(string[] args)
{
xyz t = new Test();
t.Testmethod();
Console.Write("\n\n\n");
xyz t2 = new Test2();
t2.Testmethod();
t = t2; // error occured here
Console.ReadKey();
}
}
//create a base class with virtual method
class xyz {
public virtual void Testmethod()
{
int value = 20; Console.WriteLine(value);
}
}
//inherit base class in both class
class Test:xyz
{
public override void Testmethod()
{
int value = 20; Console.WriteLine(value);
}
}
class Test2:xyz
{
public override void Testmethod()
{
int value = 40; Console.WriteLine(value);
}
}