Hey
ASP.NET 2.0
I've studied a code example in a .net book and found code I've got some
trouble with unerstanding: This is about 2 classes, one class inherit from
the class
The problem is that I cannot do this:
Message m = new Message(all the parametes goes here);
m.Id <-- this is my problem, I cannot type m.Id, because m.Id isn't
available in the inheriated class. I thought it was because the Message
class is inheriated from BaseNetwork. I can however get the Id value by
typing this. m.base.Id... but I want to type m.Id...
Any suggestions?
Below is the classes:
//This is the ancestor class
public abstract class BaseNetwork :
{
private int _id = 0;
public int ID
{
get { return _id; }
protected set { _id = value; }
}
private DateTime _addedDate = DateTime.Now;
public DateTime AddedDate
{
get { return _addedDate; }
protected set { _addedDate = value; }
}
private string _addedBy = "";
public string AddedBy
{
get { return _addedBy; }
protected set { _addedBy = value; }
}
****************************************
//This is inherited class
public class Message : BaseNetwork
{
private string _sender;
public string Sender
{
get { return _sender; }
set { _sender = value; }
}
private string _receiver;
public string Receiver
{
get { return _receiver; }
set { _receiver = value; }
}
private string _body;
public string Body
{
get { return _body; }
set { _body = value; }
}
public Message(int id, string sender, string receiver, string body, DateTime
dateAdded)
{
this.ID = id;
this.Sender = sender;
this.Receiver = receiver;
this.Body = body;
this.AddedDate = dateAdded;
}hello jeff,
on base class change property:
protected int _id = 0;
public int ID
{
get { return _id; }
set { _id = value; }
}
hope it will help...
"Jeff" wrote:
> Hey
> ASP.NET 2.0
> I've studied a code example in a .net book and found code I've got some
> trouble with unerstanding: This is about 2 classes, one class inherit from
> the class
> The problem is that I cannot do this:
> Message m = new Message(all the parametes goes here);
> m.Id <-- this is my problem, I cannot type m.Id, because m.Id isn't
> available in the inheriated class. I thought it was because the Message
> class is inheriated from BaseNetwork. I can however get the Id value by
> typing this. m.base.Id... but I want to type m.Id...
> Any suggestions?
> Below is the classes:
>
> //This is the ancestor class
> public abstract class BaseNetwork :
> {
> private int _id = 0;
> public int ID
> {
> get { return _id; }
> protected set { _id = value; }
> }
> private DateTime _addedDate = DateTime.Now;
> public DateTime AddedDate
> {
> get { return _addedDate; }
> protected set { _addedDate = value; }
> }
> private string _addedBy = "";
> public string AddedBy
> {
> get { return _addedBy; }
> protected set { _addedBy = value; }
> }
> ****************************************
> //This is inherited class
> public class Message : BaseNetwork
> {
> private string _sender;
> public string Sender
> {
> get { return _sender; }
> set { _sender = value; }
> }
> private string _receiver;
> public string Receiver
> {
> get { return _receiver; }
> set { _receiver = value; }
> }
> private string _body;
> public string Body
> {
> get { return _body; }
> set { _body = value; }
> }
> public Message(int id, string sender, string receiver, string body, DateTi
me
> dateAdded)
> {
> this.ID = id;
> this.Sender = sender;
> this.Receiver = receiver;
> this.Body = body;
> this.AddedDate = dateAdded;
> }
>
>
The names are case sensetive. Use m.ID instead of m.Id.
Jeff wrote:
> Hey
> ASP.NET 2.0
> I've studied a code example in a .net book and found code I've got some
> trouble with unerstanding: This is about 2 classes, one class inherit from
> the class
> The problem is that I cannot do this:
> Message m = new Message(all the parametes goes here);
> m.Id <-- this is my problem, I cannot type m.Id, because m.Id isn't
> available in the inheriated class. I thought it was because the Message
> class is inheriated from BaseNetwork. I can however get the Id value by
> typing this. m.base.Id... but I want to type m.Id...
> Any suggestions?
> Below is the classes:
>
> //This is the ancestor class
> public abstract class BaseNetwork :
> {
> private int _id = 0;
> public int ID
> {
> get { return _id; }
> protected set { _id = value; }
> }
> private DateTime _addedDate = DateTime.Now;
> public DateTime AddedDate
> {
> get { return _addedDate; }
> protected set { _addedDate = value; }
> }
> private string _addedBy = "";
> public string AddedBy
> {
> get { return _addedBy; }
> protected set { _addedBy = value; }
> }
> ****************************************
> //This is inherited class
> public class Message : BaseNetwork
> {
> private string _sender;
> public string Sender
> {
> get { return _sender; }
> set { _sender = value; }
> }
> private string _receiver;
> public string Receiver
> {
> get { return _receiver; }
> set { _receiver = value; }
> }
> private string _body;
> public string Body
> {
> get { return _body; }
> set { _body = value; }
> }
> public Message(int id, string sender, string receiver, string body, DateTi
me
> dateAdded)
> {
> this.ID = id;
> this.Sender = sender;
> this.Receiver = receiver;
> this.Body = body;
> this.AddedDate = dateAdded;
> }
>
>
That doesn't make any difference. See my other post in the thread for
the real reason.
Oren wrote:
> hello jeff,
> on base class change property:
> protected int _id = 0;
> public int ID
> {
> get { return _id; }
> set { _id = value; }
> }
> hope it will help...
> "Jeff" wrote:
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment