PC Review


Reply
Thread Tools Rate Thread

anyone got a minute, need some help with extention methods

 
 
Richard U
Guest
Posts: n/a
 
      2nd Jul 2011
hey guys... was wondering if anyone got a min trying to work this thing out(less then 100lines) http://pastebin.com/Jm8YQNXg ... i am trying to add aextension method which is a filter to League object to allow filtering of fighters in the League , p.s. ive included the errors in the pastebin
 
Reply With Quote
 
 
 
 
RayLopez99
Guest
Posts: n/a
 
      2nd Jul 2011
On Jul 2, 9:05*am, Richard U <richard....@gmail.com> wrote:
> hey guys... was wondering if anyone got a min trying to work this thing out (less then 100lines)http://pastebin.com/Jm8YQNXg... i am trying to add aextension method which is a filter to League object to allow filtering of fighters in the League , p.s. ive included the errors in the pastebin


I don't see what you are trying to do: where is the error, is there
an error? Then again I'm not that experienced and have done one
extension method in my life on my own, as a programming exercise. Why
do you want an extension method? Because you cannot change the
existing code otherwise or something?

Thanks for the pastebin link though, now I know about them*.

RL

*
What is Pastebin.com all about?
Pastebin.com is a website where you can store text for a certain
period of time. The website is mainly used by programmers to store
pieces of sources code or configuration information, but anyone is
more than welcome to paste any type of text. The idea behind the site
is to make it more convenient for people to share large amounts of
text online.
 
Reply With Quote
 
Registered User
Guest
Posts: n/a
 
      2nd Jul 2011
On Fri, 1 Jul 2011 23:05:34 -0700 (PDT), Richard U
<(E-Mail Removed)> wrote:

>hey guys... was wondering if anyone got a min trying to work this thing out (less then 100lines) http://pastebin.com/Jm8YQNXg ... i am trying to add a extension method
>which is a filter to League object to allow filtering of fighters in the League , p.s. ive included the errors in the pastebin


A League object contains a List<Fighter> but in the Filter method the
code doesn't reflect that relationship. Instead of
foreach (Fighter f in League)
try
foreach (Fighter f in League.Fighters)

regards
A.G.
 
Reply With Quote
 
RayLopez99
Guest
Posts: n/a
 
      2nd Jul 2011
On Jul 2, 8:33*pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:

>
> Now, as far as the question goes, it seems to me that the primary issue
> is that the type for the "this" parameter of your extension method
> doesn't make any sense. *If you want to enumerate "Fighter" instances
> from a collection, that collection should be "IEnumerable<Fighter>", not
> "IEnumerable<League>".
>
> That said, note that where you actually try to use the extension method,
> the type is of neither "IEnumerable<Fighter>" or "IEnumerable<League>".
> * You are only implementing the non-generic "IEnumerable" type, which
> won't match the parameter type for the extension method. *So even with
> the extension method fixed, your code won't compile.
>
> You either need to make the extension method's "this" parameter
> non-generic, or implement the generic "IEnumerable<Fighter>" interface
> in your "League" type.
>
> Some other things to point out about the code (in no particular order):
>


How do you know all this stuff just by eyeballing some confusing
code? You making this stuff up as you go along? Probably.

BTW, I cannot understand why Generic types <T> even exist, except for
the obvious 'you catch type safe mistakes on compile' but that's such
a weak rationale for using such a confusing looking nomenclature.

RL
 
Reply With Quote
 
Registered User
Guest
Posts: n/a
 
      2nd Jul 2011
On Sat, 2 Jul 2011 11:18:55 -0700 (PDT), RayLopez99
<(E-Mail Removed)> wrote:

>On Jul 2, 8:33*pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
>

- good stuff snipped -
>>
>> Some other things to point out about the code (in no particular order):
>>

>
>How do you know all this stuff just by eyeballing some confusing
>code? You making this stuff up as you go along? Probably.


Being able to read and understand someone else's code, tortured or
not, is a valuable asset. Pete took the time to read the code,
interpret what the code was intended to do, and then post what he
found. You should be much more appreciative of his efforts. With some
effort on your part you might learn something.

>BTW, I cannot understand why Generic types <T> even exist, except for
>the obvious 'you catch type safe mistakes on compile' but that's such
>a weak rationale for using such a confusing looking nomenclature.
>

It's the OO paradigm about not having to re-invent the wheel over and
over again. The OP could have written a FighterList type as a
type-safe for Fighter wrapper around a List type. Then the OP could
have written a LeagueList type as a type-safe for League wrapper
around a List type. Both types provide limited re-usability.

Generic types provide the same type-safe functionality in an eminently
re-usable form. A major benefit of type-safety is not having to cast
and then verify the cast for every reference to a collection member.

regards
A.G.
 
Reply With Quote
 
RayLopez99
Guest
Posts: n/a
 
      3rd Jul 2011
On Jul 2, 11:48*pm, Registered User <n4...@ix.netcom.com> wrote:
> On Sat, 2 Jul 2011 11:18:55 -0700 (PDT), RayLopez99
>
> <raylope...@gmail.com> wrote:
> >On Jul 2, 8:33*pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:

>
> - good stuff snipped -
>
>
>
> >> Some other things to point out about the code (in no particular order):

>
> >How do you know all this stuff just by eyeballing some confusing
> >code? *You making this stuff up as you go along? *Probably.

>
> Being able to read and understand someone else's code, tortured or
> not, is a valuable asset. Pete took the time to read the code,
> interpret what the code was intended to do, and then post what he
> found. You should be much more appreciative of his efforts. With some
> effort on your part you might learn something.


Doubtful Pete did anything useful. Let's wait to hear from the user.
Anybody can critique code--even beginners like you.

>
> >BTW, I cannot understand why Generic types <T> even exist, except for
> >the obvious 'you catch type safe mistakes on compile' but that's such
> >a weak rationale for using such a confusing looking nomenclature.

>
> It's the OO paradigm about not having to re-invent the wheel over and
> over again. The OP could have written a FighterList type as a
> type-safe for Fighter wrapper around a List type. Then the OP could
> have written a *LeagueList type as a type-safe for League wrapper
> around a List type. Both types provide limited re-usability.
>
> Generic types provide the same type-safe functionality in an eminently
> re-usable form. A major benefit of type-safety is not having to cast
> and then verify the cast for every reference to a collection member.


Yes you are taking about Generic Lists, which I use all the time. But
generic types in general are a waste IMO.

RL
 
Reply With Quote
 
Rick Lones
Guest
Posts: n/a
 
      3rd Jul 2011
RayLopez99 wrote:
> On Jul 2, 11:48 pm, Registered User <n4...@ix.netcom.com> wrote:
>> On Sat, 2 Jul 2011 11:18:55 -0700 (PDT), RayLopez99
>>
>> <raylope...@gmail.com> wrote:
>>> On Jul 2, 8:33 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:

>> - good stuff snipped -
>>
>>
>>
>>>> Some other things to point out about the code (in no particular order):
>>> How do you know all this stuff just by eyeballing some confusing
>>> code? You making this stuff up as you go along? Probably.

>> Being able to read and understand someone else's code, tortured or
>> not, is a valuable asset. Pete took the time to read the code,
>> interpret what the code was intended to do, and then post what he
>> found. You should be much more appreciative of his efforts. With some
>> effort on your part you might learn something.

>
> Doubtful Pete did anything useful. Let's wait to hear from the user.
> Anybody can critique code--even beginners like you.


Hmm, it seems like you have already admitted that YOU couldn't do it.
 
Reply With Quote
 
Registered User
Guest
Posts: n/a
 
      3rd Jul 2011
On Sun, 3 Jul 2011 02:55:25 -0700 (PDT), RayLopez99
<(E-Mail Removed)> wrote:

>
>Doubtful Pete did anything useful. Let's wait to hear from the user.
>Anybody can critique code--even beginners like you.
>

Peter answered the OP's question in detail and provided some
informative comments about the OP's code. Your evaluation is far from
universal and does not negate the value of Pete's explanations. He
certainly wasn't, as you've previously suggested, making things up.

I didn't critique any code, in a response to the OP I simply pointed
the obvious error.
>
>Yes you are taking about Generic Lists, which I use all the time. But
>generic types in general are a waste IMO.
>

Huh? Given the most common use of generics is to create collection
classes, the two sentences regarding generics appear to be
contradictory. You make me laugh.

regards
A.G.
 
Reply With Quote
 
RayLopez99
Guest
Posts: n/a
 
      3rd Jul 2011
On Jul 3, 6:26*pm, Registered User <n4...@ix.netcom.com> wrote:

> >Yes you are taking about Generic Lists, which I use all the time. *But
> >generic types in general are a waste IMO.

>
> Huh? Given the most common use of generics is to create collection
> classes, the two sentences regarding generics appear to be
> contradictory. You make me laugh.


Jokes on you. You just admitted you've never used a Genetic Type
outside of a collection class. Well you really should not. But you
can, and you don't even know how you can.

RL
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      4th Jul 2011
On 7/3/2011 5:55 AM, RayLopez99 wrote:
> On Jul 2, 11:48 pm, Registered User<n4...@ix.netcom.com> wrote:
>> Generic types provide the same type-safe functionality in an eminently
>> re-usable form. A major benefit of type-safety is not having to cast
>> and then verify the cast for every reference to a collection member.

>
> Yes you are taking about Generic Lists, which I use all the time. But
> generic types in general are a waste IMO.


From the practical perspective it is difficult to support generic
collections without supporting generics.

But besides that generics can also be useful outside
collections.

General reading and writing methods is one example.

Usage outside of collections may not justify the extra complexity,
but having the feature for collections makes it cost free for other
usage.

Arne

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: anyone got a minute, need some help with extention methods Richard U Microsoft C# .NET 0 5th Jul 2011 01:51 PM
System time(minute) change event doesn't raise per minute. =?Utf-8?B?THVja2Nhbw==?= Microsoft Dot NET Compact Framework 1 5th Jul 2007 04:49 PM
Is it possible to make generalized methods that accept parameterized references to call other methods? Microsoft C# .NET 3 22nd Jun 2007 11:19 PM
How to change Fifteen minute timer slide to Twenty minute? =?Utf-8?B?Skw=?= Microsoft Powerpoint 6 31st Oct 2006 01:17 PM
To convert minute into hour and minute =?Utf-8?B?THljbw==?= Microsoft Excel Misc 2 27th Nov 2003 06:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:24 PM.