Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

How generics can be used in our application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bhuwan Bhaskar - 07 Oct 2007 10:16 GMT
Hi,

What are generics? How generics can be used in our application?

Thanks & Regards
Bhuwan
Göran Andersson - 07 Oct 2007 14:53 GMT
> Hi,
>
> What are generics? How generics can be used in our application?
>
> Thanks & Regards
> Bhuwan

http://www.google.com/search?q=generics+c%23

Signature

Göran Andersson
_____
http://www.guffa.com

Scott M. - 07 Oct 2007 16:26 GMT
Do you have a need for strongly-type collections of things?

If so, generics are for you.

> Hi,
>
> What are generics? How generics can be used in our application?
>
> Thanks & Regards
> Bhuwan
Peter Duniho - 07 Oct 2007 18:04 GMT
>> Hi,
>>
[quoted text clipped - 3 lines]
>
> If so, generics are for you.

Sure, but generics are a lot more than that.  The most visible example
of the use of generics in C# are the generic collections, but that's
just one example of how one might use generics.

A very simple answer, for someone that is already familiar with C++
templates, is that generics address a similar need.  So where you'd use
a template in C++, you can use generics in C# (generally speaking).

And if you're not already familiar with C++ templates, the reason you'd
use templates or generics is to implement code that can be written in a
generic way (hence the name), not specific to the type that will
actually be used in the concrete use of the code.  Then you can reuse
that code without creating new versions of it for each concrete type for
which it's going to be used.

In addition to that reuse advantage, generics also have the advantage
that for reference types the same compiled code is used for all uses of
the generic type (as opposed to doing "copy, paste, search and replace"
which produces a whole new instance of the compiled code for each use).

It's hard to sum up every way in which generics are useful in a single
post, but hopefully the above does some justice to the question.  I
would definitely agree that the next step for anyone considering the
question is to read the MSDN documentation on the topic.

Pete
Scott M. - 08 Oct 2007 19:50 GMT
The OP was so vauge, I didn't bother to go into details.  It sounds like the
OP isn't even sure of what he needs to do, so I just gave him a carrot to
nibble on.

>>> Hi,
>>>
[quoted text clipped - 30 lines]
>
> Pete
sloan - 08 Oct 2007 03:14 GMT
public class Employee{}

public class EmployeeCollection : List<Employee>
{

}

instantiate an instance of EmployeeCollection, and see all the wonderful
methods, that are STRONGLY TYPED.

ex:

EmployeeCollection ec = new EmployeeCollection();

Employee e = new Employee();

ec.Add ( e ) ; //<< Notice the add takes an Employee as a param, not an
"object".

That's def not the only thinng you can do. but its a start.  The benefit is
that anytime you need a collection, all you do is this:

List < MyCustomObject > = new List <MyCustomObject >();
//or use my method above of EmployeeCollection.

Because you get strong typing, your code is alot less buggy.

Check this blog entry out:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!151.entry

It gives you access to the Session object, but in a strongly typed way ...

But you can also see how to use generics in a slightly different way that
just collection based ones.

> Hi,
>
> What are generics? How generics can be used in our application?
>
> Thanks & Regards
> Bhuwan

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.