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 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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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:...
|
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...
|
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...
|
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...
|
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...
|
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%...
|
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.
|
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...
|
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?
|
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...
|
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,...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |