× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, Jan 12, 2010 at 5:29 PM, Hans Boldt <hans@xxxxxxxxxx> wrote:


What about C#? My opinion is that the language designers at Microsoft
looked at all possible OO language features, couldn't agree on which
were important, and then decided to include them all.

which ones should not be in the language? Extension methods?
Anonymous types? Lamda expressions? Interfaces? Nullable types?
Generics?

When you see how effectively LINQ works by incorporating just about
every language feature that has been added since the initial release,
I think you are hard pressed to decide which feature the language
should be without.

The yield return op code is one of my favorites in its neatness ( and,
I think, is unique to C# ). Here is an extension method which returns
an IEnumerable interface to a sequence of Int which is parsed from a
string of comma separated numbers:

public static IEnumerable<int?> ParseLine(this string InLine)
{
string[] splitItems = InLine.Split(',');
foreach (string item in splitItems)
{
int? itemIntValue = item.DefaultParse();
yield return itemIntValue;
}
}

// DefaultParse is a method that extends the string class.
// It returns the integer value parsed from a string.
// If the string cant be parsed, it returns a null.
// The ? after int? makes the int a nullable type.
public static int? DefaultParse(this string InText)
{
int answer;
bool rv = int.TryParse(InText, out answer);
if (rv == true)
return answer;
else
return default(int?);
}

to use the method:
string textLine = "123,213,33,3534" ;
foreach( int? item in textLine.ParseLine( ))
{
if ( item == null )
MessageBox.Show("item could not be parsed") ;
else
MessageBox.Show( item.Value ) ;
}

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.