473,387 Members | 1,742 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.

Whidbey C# Generics/Iterators Question

Hello,
I got my hands on the PDC preview version of whidbey and I think I managed
to break the compiler/runtime with my first Generics/Iterators attempt. The
reason I am posting it here is that I might be wrong, in which case, please
correct me!

The following program prints garbade instead the intended 5,6,1. I think it
is printing the integer values of the pointers which represent some
references... Any ideas?

using System;
using System.Collections.Generic;

namespace test2
{
class List<T>: IEnumerable<T>, IEnumerable<ListNode<T>>
{
protected ListNode<T> _head;
protected ListNode<T> _last;

public List ()
{
}

public void Add (T _value)
{
if (_head == null)
_head = _last = new ListNode<T>(_value, null);
else
_last = _last.Next = new ListNode<T>(_value, null);
}

IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
for (ListNode<T> _current = _head; _current != null; _current =
_current.Next)
yield _current.Value;

/*
foreach (ListNode<T> n in (IEnumerable<ListNode<T>>)this)
yield n.Value;
*/
}

IEnumerator<ListNode<T>> IEnumerable<ListNode<T>>.GetEnumerator()
{
for (ListNode<T> _current = _head; _current != null; _current =
_current.Next)
yield _current;
}
}

class ListNode<T>
{
protected T _value;
protected ListNode<T> _next;

public ListNode (T _value, ListNode<T> _next)
{
Value = _value;
Next = _next;
}

public T Value
{
get
{
return _value;
}
set
{
_value = value;
}
}

public ListNode<T> Next
{
get
{
return _next;
}
set
{
_next = value;
}
}
}

class Class1
{
[STAThread]
static void Main(string[] args)
{
List<int> l = new List<int>();

l.Add(5);
l.Add(6);
l.Add(1);

foreach (int q in (IEnumerable<int>)l)
Console.WriteLine(q);
}
}
}
Nov 15 '05 #1
1 1314
You should post this to the microsoft.beta.whidbey.generics newsgroup, not
to the public csharp group.

Bruno.

"Kamen Yotov" <ka***@yotov.org> a écrit dans le message de
news:e7**************@tk2msftngp13.phx.gbl...
Hello,
I got my hands on the PDC preview version of whidbey and I think I managed
to break the compiler/runtime with my first Generics/Iterators attempt. The reason I am posting it here is that I might be wrong, in which case, please correct me!

The following program prints garbade instead the intended 5,6,1. I think it is printing the integer values of the pointers which represent some
references... Any ideas?

using System;
using System.Collections.Generic;

namespace test2
{
class List<T>: IEnumerable<T>, IEnumerable<ListNode<T>>
{
protected ListNode<T> _head;
protected ListNode<T> _last;

public List ()
{
}

public void Add (T _value)
{
if (_head == null)
_head = _last = new ListNode<T>(_value, null);
else
_last = _last.Next = new ListNode<T>(_value, null);
}

IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
for (ListNode<T> _current = _head; _current != null; _current =
_current.Next)
yield _current.Value;

/*
foreach (ListNode<T> n in (IEnumerable<ListNode<T>>)this)
yield n.Value;
*/
}

IEnumerator<ListNode<T>> IEnumerable<ListNode<T>>.GetEnumerator()
{
for (ListNode<T> _current = _head; _current != null; _current =
_current.Next)
yield _current;
}
}

class ListNode<T>
{
protected T _value;
protected ListNode<T> _next;

public ListNode (T _value, ListNode<T> _next)
{
Value = _value;
Next = _next;
}

public T Value
{
get
{
return _value;
}
set
{
_value = value;
}
}

public ListNode<T> Next
{
get
{
return _next;
}
set
{
_next = value;
}
}
}

class Class1
{
[STAThread]
static void Main(string[] args)
{
List<int> l = new List<int>();

l.Add(5);
l.Add(6);
l.Add(1);

foreach (int q in (IEnumerable<int>)l)
Console.WriteLine(q);
}
}
}

Nov 15 '05 #2

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

Similar topics

11
by: andrew queisser | last post by:
I've read some material on the upcoming Generics for C#. I've seen two types of syntax used for constraints: - direct specification of the interface in the angle brackets - where clauses I...
2
by: David Laub | last post by:
A zillion developers including me are sold on "generics" When can we start developing with them?
9
by: Mark | last post by:
Is there a .NET 2.0 newsgroup? I'd like to get an answer to the question below. Thanks in advance. - mark ******************************** I'm looking at the CodeDom namespace in .NET 2.0...
1
by: Paul | last post by:
I am about to start a new greenfield application. The big question is do I start on VS2005 CTP or not I know the final release isn't until 2005 but a cursory glance makes it seem that ASP.NET in...
19
by: Chris Dunaway | last post by:
Just got my hands on Whidbey. Here are a few interesting changes that you may not be aware of: 1. Continue statement on Do, For and While commands 2. Default Instances of certain classes...
9
by: CJ Taylor | last post by:
So yeah... finally started playing with Whidbey full on this weekend... anyone else notice that Web Developer gave you pretty much every tool you could ever want? I prototyped an entire data...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.