473,397 Members | 1,960 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,397 software developers and data experts.

Question about Generics

Public Class Some(Of t)

Inherits System.Windows.Forms.UserControl

....

DirectCast(ListBox1.Items(ListBox1.SelectedIndex), t).xyz = TextBox1.Text

....

TextBox1.Text = DirectCast(ListBox1.SelectedItem, t).xyz

At edit time the above statements produce an error that xyz is not a member
of t.

It works OK if instead of genetics I use, in place of t, an actual type that
has an xyz property.

How should I do this with generics?

thanks
Nov 6 '07 #1
2 905
"Academia" <ac************@a-znet.comschrieb:
Public Class Some(Of t)

Inherits System.Windows.Forms.UserControl
...
DirectCast(ListBox1.Items(ListBox1.SelectedIndex), t).xyz = TextBox1.Text
Defining and Using Generics in Visual Basic 2005
<URL:http://msdn2.microsoft.com/en-us/library/ms379608(vs.80).aspx#vb2005_generics_topic4>
-"Constraints"

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 6 '07 #2
Thanks for the info
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
"Academia" <ac************@a-znet.comschrieb:
>Public Class Some(Of t)

Inherits System.Windows.Forms.UserControl
...
DirectCast(ListBox1.Items(ListBox1.SelectedIndex) , t).xyz = TextBox1.Text

Defining and Using Generics in Visual Basic 2005
<URL:http://msdn2.microsoft.com/en-us/library/ms379608(vs.80).aspx#vb2005_generics_topic4>
-"Constraints"

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 7 '07 #3

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

Similar topics

5
by: Matthew W. Jackson | last post by:
I had a question about the "using" statement and Generics in the next version of C#, and I was directed to this newsgroup. My question is: Will the following syntax be valid? using...
16
by: bigtexan | last post by:
I would like to do the following and cannot figure it out. public class A<T> { public delegate T GetValueDelegate(A<T> var); public GetValueDelegate GetValue = new GetValueDelegate(B.GetValue);...
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...
1
by: Peter Kirk | last post by:
Hi I have never used generics before, and I was wondering if the following sort of use was acceptable/normal for a method: public IList<IPerson> GetPersons() { IList<IPerson> personList =...
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...
11
by: hammad.awan_nospam | last post by:
Hello, I'm wondering if it's possible to do the following with Generics: Let's say I have a generic member variable as part of a generic class like this: List<DLinqQuery<TDataContext>>...
3
by: Showjumper | last post by:
Back in asp.net 1.1 i made custom collection classes per Karl Seguin's article On the Way to Mastering ASP.NET: Introducing Custom Entity Classes to take advantage of strongly typed data. Now with...
1
by: Kevin S. Goff | last post by:
Hi, all, Hopefully this will make sense: I have 2 classes that implement the same generic interface. public interface IAgingReport<T> { T GetAgingReport(DateTime dAsOfDate); }
14
by: cwineman | last post by:
Hello, I'm hoping to do something using Generics, but I'm not sure it's possible. Let's say I want to have a bunch of business objects and a data access class cooresponding to each business...
4
by: DeveloperX | last post by:
I'm having a play with EventHandlerList but the documentation is a bit ropey and I can't find any decent examples. It also doesn't seem to do what I was led to believe it would. I was under the...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.