473,405 Members | 2,300 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,405 software developers and data experts.

new constraint in generics

Hi all!

How can i specify, that the generic class have the constructor?
With c# it's a new constraint.

For instance, i write
Expand|Select|Wrap|Line Numbers
  1. Class cls1(Of T)
  2. Public Sub some()
  3. Dim tt As New T() ' here is an error: 'New' cannot be used on a
  4. type parameter not declared 'As New()'.
  5. End Sub
  6. End Class
  7.  
Ok. Next try
Expand|Select|Wrap|Line Numbers
  1. Class cls1(Of T as New()) ' another error: Keyword does not name a type.
  2. Public Sub some()
  3. Dim tt As New T() 'previos error still here
  4. End Sub
  5. End Class
  6.  
Now i have two error message!

Can anyone help?

P.S. My versions is VS.NET Whidbey 8.0.30703.4. and the .NET Framework
1.2.30703
Nov 20 '05 #1
3 2820
* "Alex Shirshov" <qq****@mail.ru> scripsit:
How can i specify, that the generic class have the constructor?
With c# it's a new constraint.


I would suggest to post the question to one of the Longhorn communities:

<http://longhorn.msdn.microsoft.com/lhsdk/port_communities.aspx>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Alex,
How can i specify, that the generic class have the constructor?


This didn't work in the PDC alpha release, but I believe it will in a
future beta release.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #3
Errata:

I feel sorry for posting the wrong link...

<http://communities.microsoft.com/newsgroups/default.asp?icp=whidbey&slcid=us>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

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

Similar topics

1
by: Dmitry Martynov | last post by:
What if I have some special constructors and do not have a default constructor. It seems to be very useful when I do not want to forget to initialize some fields properly. As I have understood...
1
by: Ole Andre Karlson | last post by:
Hi Im using Whidbey version 8.0.30703.27, working with C# 2.0. I discovered that creating an object through the constructor constraint is a sloooow process... Is this just because I'm working...
2
by: Bernhard Huemer | last post by:
using System; using System.Collections.Generic; public class CovariantList<T> : List<T> { // ... // of course this constraint won't work .. public CovariantList<U> Convert<U>() where U:...
9
by: Alon Fliess | last post by:
Hi I am trying to write a generic class that instantiates the generic type, but I can not find the correct way to give it the constructor constraint. For example: In C#: class X<T> where...
4
by: Jethro Guo | last post by:
C++ template use constraint by signature,It's very flexible to programmer but complex for complier, and at most time programmer can not get clear error message from complier if error occur. C#...
7
by: Rune B | last post by:
Hi Group. I would like to do the following: public static DecriptiveCollection GetValuesForDisplay<T>() where T : System.Enum { DecriptiveCollection list = new DecriptiveCollection ();...
2
by: Joe Bloggs | last post by:
Hi, compiling the following code: public class App { static void Main() { int? x = 5; bool? i = null;
8
by: Sam Kong | last post by:
Hello, I want to define a generic class which should accept only nullable types or reference types. What's the best way to costrain it? --------- class MyClass<T>{ ...
3
by: Michael Moreno | last post by:
hello, I am trying to write a generic class where the underlying type is either an int, a float or a double: public class CMatrix<T>: ICloneable where VarType: int, float, double but that...
5
by: Siegfried Heintze | last post by:
On line 5 of the program below I get the error message in the subject line. (1) How may I correct it? (2) How may I enhance my Arr class to work with a foreach statement? (3) In C++ I can pass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.