473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Class ... Why is this not working?

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
Jun 27 '08 #1
16 1481
On Jun 25, 11:14 am, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #2
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #3

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" <md*****@gmail.comwrote in message
news:e6**********************************@m36g2000 hse.googlegroups.com...
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

Jun 27 '08 #4
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #5
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #6
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #7
On Jun 25, 4:44*pm, shapper <mdmo...@gmail.comwrote:
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #8
On Jun 25, 4:44*pm, shapper <mdmo...@gmail.comwrote:
On Jun 25, 4:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:14*pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #9
On Jun 25, 4:56 pm, shapper <mdmo...@gmail.comwrote:

<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
Jun 27 '08 #10
On Jun 25, 4:44 pm, shapper <mdmo...@gmail.comwrote:
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?
No, it shouldn't. (It would have been helpful to explain that you were
trying to use an object initializer in your first post, btw - this is
where short but complete examples come in very handy.)

You can do:

select new TagPaper { Tag = t, Tie = { Count = { File =
t.FileTag.Count } } }

That's the proper syntax for setting properties on embedded objects.

Jon
Jun 27 '08 #11
On Jun 25, 5:07*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:56 pm, shapper <mdmo...@gmail.comwrote:

<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.
Seehttp://csharpindepth.com/Articles/Chapter1/Versions.aspx

Jon
I think I got it ... I changed my LINQ procedure to:

TagPaper paper = (from t in database.Tags
where t.TagID == id
select new TagPaper {
Tag = t,
new Tie {
new Count {
File = t.FileTag.Count
}
}
}).SingleOrDefault();

Now it does not give me any error ...

Jon, I will read what you sent me ... Ok, C# 3.0.
Jun 27 '08 #12
On Jun 25, 5:15*pm, shapper <mdmo...@gmail.comwrote:
On Jun 25, 5:07*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:56 pm, shapper <mdmo...@gmail.comwrote:
<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.
Seehttp://csharpindepth.com/Articles/Chapter1/Versions.aspx
Jon

I think I got it ... I changed my LINQ procedure to:

* * * TagPaper paper = (from t in database.Tags
* * * * * * * * * * * * where t.TagID == id
* * * * * * * * * * * * select new TagPaper {
* * * * * * * * * * * * * Tag = t,
* * * * * * * * * * * * * new Tie {
* * * * * * * * * * * * * * new Count {
* * * * * * * * * * * * * * * File = t.FileTag.Count
* * * * * * * * * * * * * * }
* * * * * * * * * * * * * }
* * * * * * * * * * * * }).SingleOrDefault();

Now it does not give me any error ...

Jon, I will read what you sent me ... Ok, C# 3.0.
Thanks Jon.

Yes I know but I though the problem was with my classes ... I am just
moving from VB.NET to C# since I started to use MVC ...

Thank you for the help!
Miguel
Jun 27 '08 #13
On Jun 25, 5:15 pm, shapper <mdmo...@gmail.comwrote:
I think I got it ... I changed my LINQ procedure to:

TagPaper paper = (from t in database.Tags
where t.TagID == id
select new TagPaper {
Tag = t,
new Tie {
new Count {
File = t.FileTag.Count
}
}
}).SingleOrDefault();

Now it does not give me any error ...
It should. It certainly does in my test program.

It should be "Tie = {" rather than "new Tie {" and the same for Count.
(You could equally do "Tie = new Tie {" which is subtly different,
setting the Tie property rather than merely setting properties within
the existing value.)

Jon
Jun 27 '08 #14
Ok, I didn't realize you were there yet.

And I'm a little behind in the 3.5 (framework).


"shapper" <md*****@gmail.comwrote in message
news:2b**********************************@b1g2000h sg.googlegroups.com...
On Jun 25, 4:44 pm, shapper <mdmo...@gmail.comwrote:
On Jun 25, 4:23 pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 4:14 pm, shapper <mdmo...@gmail.comwrote:
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
Jun 27 '08 #15
On Jun 25, 5:23*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 5:15 pm, shapper <mdmo...@gmail.comwrote:
I think I got it ... I changed my LINQ procedure to:
* * * TagPaper paper = (from t in database.Tags
* * * * * * * * * * * * where t.TagID == id
* * * * * * * * * * * * select new TagPaper {
* * * * * * * * * * * * * Tag = t,
* * * * * * * * * * * * * new Tie {
* * * * * * * * * * * * * * new Count {
* * * * * * * * * * * * * * * File = t.FileTag.Count
* * * * * * * * * * * * * * }
* * * * * * * * * * * * * }
* * * * * * * * * * * * }).SingleOrDefault();
Now it does not give me any error ...

It should. It certainly does in my test program.

It should be "Tie = {" rather than "new Tie {" and the same for Count.
(You could equally do "Tie = new Tie {" which is subtly different,
setting the Tie property rather than merely setting properties within
the existing value.)

Jon
In fact it must be:
TagPaper paper = (from t in database.Tags
where t.TagID == id
select new TagPaper {
Tag = t,
Tie = new Tie { Count = new Count{ File =
t.FileTag.Count } }
}).SingleOrDefault();

If I don't use new Tie:

TagPaper paper = (from t in database.Tags
where t.TagID == id
select new TagPaper {
Tag = t,
Tie = { Count = { File = t.FileTag.Count } }
}).SingleOrDefault();

I get the error: System.InvalidOperationException: Unhandled binding
type: MemberBinding

So I think there is no way around it ... must use new.

Thanks,
Miguel
Jun 27 '08 #16
shapper <md*****@gmail.comwrote:
In fact it must be:
TagPaper paper = (from t in database.Tags
where t.TagID == id
select new TagPaper {
Tag = t,
Tie = new Tie { Count = new Count{ File =
t.FileTag.Count } }
}).SingleOrDefault();
Well, that depends on the context.
If I don't use new Tie:

TagPaper paper = (from t in database.Tags
where t.TagID == id
select new TagPaper {
Tag = t,
Tie = { Count = { File = t.FileTag.Count } }
}).SingleOrDefault();

I get the error: System.InvalidOperationException: Unhandled binding
type: MemberBinding

So I think there is no way around it ... must use new.
If you're using LINQ to SQL, it looks like it. That would be fine for
LINQ to Objects - it's valid C#, just not a pattern LINQ to SQL
recognises.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: S. Levent Yilmaz | last post by:
Is it possible to have the constructor in an interface call member functions polymorphically? For instance: ============================== // INTERFACE CLASS class SomeInterface { public:...
0
by: david chang via DotNetMonster.com | last post by:
Hi, guys I am trapped into a big trouble on how to use unmanaged class library code in a C# web application. Now, I am working on a project to develop a web interface for SPlus, a statistical...
9
by: Jim Starcher | last post by:
I cannot get the intellisense hints to work on my class constructors. Would you please tell me what I am doing wrong? public class MyObject { //Constructors /// <summary> /// Used to...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
29
by: Michael D. Ober | last post by:
Is there any way to create a constant in a class that can be used both with an instantiated object and without. For example: dim ClassConst as string = myClass.ConstantString dim myObj = new...
15
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
4
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi How can I declare a CDialog object as a member of a managed class? As the following is not working: RbfPropDlg* rbfDlg; Where RbfPropDlg is the CDialog class.
6
by: Charles D Hixson | last post by:
I'm trying to construct read-only variables at the class level. I've been unsuccessful. Any suggestions? Mixing @classmethod and @property doesn't appear to produce workable code. Ditto for...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.