PC Review


Reply
Thread Tools Rate Thread

Class ... Why is this not working?

 
 
shapper
Guest
Posts: n/a
 
      25th Jun 2008
Hello,

I have the following classes:

namespace MyApp.Models {
public class Tie {
public Count Count { get; set; }
public Tie() {
this.Count = new Count();
}
}
}
namespace MyApp.Models
{
public class Count
{
public int File { get; set; }
public int Professor { get; set; }
}
}

However, when I access the Tie class in my code the only think Visual
Studio recognizes is:
Tie.Tie.Tie ...

Why can't I access Tie.Count ?

The Tie method inside the Tie class is only a constructor to
initialize the Count property.

Am I doing something wrong?

I have been using VB.NET for a long time and C# just recently so I am
still getting familiar with it.

Thanks,
Miguel
 
Reply With Quote
 
 
 
 
parez
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 11:14 am, shapper <mdmo...@gmail.com> wrote:
> Hello,
>
> I have the following classes:
>
> namespace MyApp.Models {
> public class Tie {
> public Count Count { get; set; }
> public Tie() {
> this.Count = new Count();
> }
> }}
>
> namespace MyApp.Models
> {
> public class Count
> {
> public int File { get; set; }
> public int Professor { get; set; }
> }
>
> }
>
> However, when I access the Tie class in my code the only think Visual
> Studio recognizes is:
> Tie.Tie.Tie ...
>
> Why can't I access Tie.Count ?
>
> The Tie method inside the Tie class is only a constructor to
> initialize the Count property.
>
> Am I doing something wrong?
>
> I have been using VB.NET for a long time and C# just recently so I am
> still getting familiar with it.
>
> Thanks,
> Miguel


try instantiating a Tie class then try to access;

Tie tie = new Tie();
tie.Count
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.com> wrote:
> I have the following classes:
>
> namespace MyApp.Models {
> * public class Tie {
> * * public Count Count { get; set; }
> * * public Tie() {
> * * * this.Count = new Count();
> * * }
> * }}
>
> namespace MyApp.Models
> {
> * public class Count
> * {
> * * public int File { get; set; }
> * * public int Professor { get; set; }
> * }
>
> }
>
> However, when I access the Tie class in my code the only think Visual
> Studio recognizes is:
> Tie.Tie.Tie ...
>
> Why can't I access Tie.Count ?


Count is an instance property - so you should be able to do:

Tie someTie = new Tie();
Count count = someTie.Count;

But you can't do:

Count count = Tie.Count;

Jon
 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      25th Jun 2008

Since this is newer to you, I'm gonna try to post what I think you're after.
I"m not sure though.

I renamed one thing to "TheCount" so we can avoid ambiguity in the
discussion.



Tie t1 = new Tie();

Console.WriteLine(t1.TheCount.File);

Console.WriteLine(t1.TheCount.Professor);






public class Tie

{

private Count _count1 = null;

public Count TheCount

{

get

{

return _count1;

}

set

{

_count1 = value;

}

}



public Tie()

{

this.TheCount = new Count();

}

}



public class Count

{

private int _file = 0;

private int _prof = 0;

public int File

{

get

{

return _file;

}

set

{

_file = value;

}

}



public int Professor

{

get

{

return _prof;

}

set

{

_prof = value;

}

}





}



"shapper" <(E-Mail Removed)> wrote in message
news:e6a85e48-2e29-4634-8395-(E-Mail Removed)...
> Hello,
>
> I have the following classes:
>
> namespace MyApp.Models {
> public class Tie {
> public Count Count { get; set; }
> public Tie() {
> this.Count = new Count();
> }
> }
> }
> namespace MyApp.Models
> {
> public class Count
> {
> public int File { get; set; }
> public int Professor { get; set; }
> }
> }
>
> However, when I access the Tie class in my code the only think Visual
> Studio recognizes is:
> Tie.Tie.Tie ...
>
> Why can't I access Tie.Count ?
>
> The Tie method inside the Tie class is only a constructor to
> initialize the Count property.
>
> Am I doing something wrong?
>
> I have been using VB.NET for a long time and C# just recently so I am
> still getting familiar with it.
>
> Thanks,
> Miguel



 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
> On Jun 25, 4:14*pm, shapper <mdmo...@gmail.com> wrote:
>
>
>
> > I have the following classes:

>
> > namespace MyApp.Models {
> > * public class Tie {
> > * * public Count Count { get; set; }
> > * * public Tie() {
> > * * * this.Count = new Count();
> > * * }
> > * }}

>
> > namespace MyApp.Models
> > {
> > * public class Count
> > * {
> > * * public int File { get; set; }
> > * * public int Professor { get; set; }
> > * }

>
> > }

>
> > However, when I access the Tie class in my code the only think Visual
> > Studio recognizes is:
> > Tie.Tie.Tie ...

>
> > Why can't I access Tie.Count ?

>
> Count is an instance property - so you should be able to do:
>
> Tie someTie = new Tie();
> Count count = someTie.Count;
>
> But you can't do:
>
> Count count = Tie.Count;
>
> Jon


I am trying to do the following:

data.TagPapers = (from t in
database.Tags
select new TagPaper {
Tag = t,
Tie.Count.File =
t.FileTag.Count
}).ToList

Where TagPapers is a List of TagPaper which is a class with 2
properties: Tag and Tie.

Shouldn't this be working?

It is not working on Tie.Count.File

I have no idea what is wrong. It seems right to me.

Any idea?

Thanks,
Miguel
 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
> On Jun 25, 4:14*pm, shapper <mdmo...@gmail.com> wrote:
>
>
>
> > I have the following classes:

>
> > namespace MyApp.Models {
> > * public class Tie {
> > * * public Count Count { get; set; }
> > * * public Tie() {
> > * * * this.Count = new Count();
> > * * }
> > * }}

>
> > namespace MyApp.Models
> > {
> > * public class Count
> > * {
> > * * public int File { get; set; }
> > * * public int Professor { get; set; }
> > * }

>
> > }

>
> > However, when I access the Tie class in my code the only think Visual
> > Studio recognizes is:
> > Tie.Tie.Tie ...

>
> > Why can't I access Tie.Count ?

>
> Count is an instance property - so you should be able to do:
>
> Tie someTie = new Tie();
> Count count = someTie.Count;
>
> But you can't do:
>
> Count count = Tie.Count;
>
> Jon


I am trying to do the following:

data.TagPapers = (from t in
database.Tags
select new TagPaper {
Tag = t,
Tie.Count.File =
t.FileTag.Count
}).ToList

Where TagPapers is a List of TagPaper which is a class with 2
properties: Tag and Tie.

Shouldn't this be working?

It is not working on Tie.Count.File

I have no idea what is wrong. It seems right to me.

Any idea?

Thanks,
Miguel
 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
> On Jun 25, 4:14*pm, shapper <mdmo...@gmail.com> wrote:
>
>
>
> > I have the following classes:

>
> > namespace MyApp.Models {
> > * public class Tie {
> > * * public Count Count { get; set; }
> > * * public Tie() {
> > * * * this.Count = new Count();
> > * * }
> > * }}

>
> > namespace MyApp.Models
> > {
> > * public class Count
> > * {
> > * * public int File { get; set; }
> > * * public int Professor { get; set; }
> > * }

>
> > }

>
> > However, when I access the Tie class in my code the only think Visual
> > Studio recognizes is:
> > Tie.Tie.Tie ...

>
> > Why can't I access Tie.Count ?

>
> Count is an instance property - so you should be able to do:
>
> Tie someTie = new Tie();
> Count count = someTie.Count;
>
> But you can't do:
>
> Count count = Tie.Count;
>
> Jon


I am trying to do the following:

data.TagPapers = (from t in
database.Tags
select new TagPaper {
Tag = t,
Tie.Count.File =
t.FileTag.Count
}).ToList

Where TagPapers is a List of TagPaper which is a class with 2
properties: Tag and Tie.

Shouldn't this be working?

It is not working on Tie.Count.File

I have no idea what is wrong. It seems right to me.

Any idea?

Thanks,
Miguel
 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:44*pm, shapper <mdmo...@gmail.com> wrote:
> On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
>
>
>
> > On Jun 25, 4:14*pm, shapper <mdmo...@gmail.com> wrote:

>
> > > I have the following classes:

>
> > > namespace MyApp.Models {
> > > * public class Tie {
> > > * * public Count Count { get; set; }
> > > * * public Tie() {
> > > * * * this.Count = new Count();
> > > * * }
> > > * }}

>
> > > namespace MyApp.Models
> > > {
> > > * public class Count
> > > * {
> > > * * public int File { get; set; }
> > > * * public int Professor { get; set; }
> > > * }

>
> > > }

>
> > > However, when I access the Tie class in my code the only think Visual
> > > Studio recognizes is:
> > > Tie.Tie.Tie ...

>
> > > Why can't I access Tie.Count ?

>
> > Count is an instance property - so you should be able to do:

>
> > Tie someTie = new Tie();
> > Count count = someTie.Count;

>
> > But you can't do:

>
> > Count count = Tie.Count;

>
> > Jon

>
> I am trying to do the following:
>
> * * * data.TagPapers = (from t in
> database.Tags
> * * * * * * * * * * * * * * * * * select new TagPaper {
> * * * * * * * * * * * * * * * * * * Tag = t,
> * * * * * * * * * * * * * * * * * * Tie.Count.File =
> t.FileTag.Count
> * * * * * * * * * * * * * * * * *}).ToList
>
> Where TagPapers is a List of TagPaper which is a class with 2
> properties: Tag and Tie.
>
> Shouldn't this be working?
>
> It is not working on Tie.Count.File
>
> I have no idea what is wrong. It seems right to me.
>
> Any idea?
>
> Thanks,
> Miguel


Sloan,

But since, I think, NET 3.0 there are automatic properties so you
don't need all those variables:
http://weblogs.asp.net/scottgu/archi...tializers.aspx

That was what I was doing.

Thanks,
Miguel
 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:44*pm, shapper <mdmo...@gmail.com> wrote:
> On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
>
>
>
> > On Jun 25, 4:14*pm, shapper <mdmo...@gmail.com> wrote:

>
> > > I have the following classes:

>
> > > namespace MyApp.Models {
> > > * public class Tie {
> > > * * public Count Count { get; set; }
> > > * * public Tie() {
> > > * * * this.Count = new Count();
> > > * * }
> > > * }}

>
> > > namespace MyApp.Models
> > > {
> > > * public class Count
> > > * {
> > > * * public int File { get; set; }
> > > * * public int Professor { get; set; }
> > > * }

>
> > > }

>
> > > However, when I access the Tie class in my code the only think Visual
> > > Studio recognizes is:
> > > Tie.Tie.Tie ...

>
> > > Why can't I access Tie.Count ?

>
> > Count is an instance property - so you should be able to do:

>
> > Tie someTie = new Tie();
> > Count count = someTie.Count;

>
> > But you can't do:

>
> > Count count = Tie.Count;

>
> > Jon

>
> I am trying to do the following:
>
> * * * data.TagPapers = (from t in
> database.Tags
> * * * * * * * * * * * * * * * * * select new TagPaper {
> * * * * * * * * * * * * * * * * * * Tag = t,
> * * * * * * * * * * * * * * * * * * Tie.Count.File =
> t.FileTag.Count
> * * * * * * * * * * * * * * * * *}).ToList
>
> Where TagPapers is a List of TagPaper which is a class with 2
> properties: Tag and Tie.
>
> Shouldn't this be working?
>
> It is not working on Tie.Count.File
>
> I have no idea what is wrong. It seems right to me.
>
> Any idea?
>
> Thanks,
> Miguel


Sloan,

But since, I think, NET 3.0 there are automatic properties so you
don't need all those variables:
http://weblogs.asp.net/scottgu/archi...tializers.aspx

That was what I was doing.

Thanks,
Miguel
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 4:56 pm, shapper <mdmo...@gmail.com> wrote:

<snip>

> But since, I think, NET 3.0 there are automatic properties so you
> don't need all those variables:http://weblogs.asp.net/scottgu/archi...-orcas-languag...


Careful of terminology - automatic properties are part of C# 3.0,
not .NET 3.0.
See http://csharpindepth.com/Articles/Ch.../Versions.aspx

Jon
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
App_Code Class not working Matthew Microsoft ASP .NET 4 24th Sep 2006 07:58 PM
ImageList in base class not working correctly in inherited class =?Utf-8?B?QnJ1Y2UgUGFya2Vy?= Microsoft Dot NET Framework Forms 3 16th Dec 2005 02:20 AM
Monitor class not working as specified I.Benc Microsoft Dot NET Framework 1 9th Dec 2004 06:49 PM
Working With Class Modules =?Utf-8?B?RGV2bGlu?= Microsoft Access VBA Modules 1 4th Nov 2004 02:04 PM
Why is COM class not working? Amil Microsoft Dot NET Framework 0 10th Feb 2004 09:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:22 AM.