Steveluo’s Blog

Just another WordPress.com weblog

Archive for the ‘Uncategorized’ Category

C#, Java, C++ Performance

Posted by steveluo on August 23, 2009

1) C#, Java and C++
Microbenchmarking C++, C#, and Java   (DDJ 2005 )
C# versus C++ versus Java performance comparison
Java Performance
The Computer Language Benchmarks Game
Debunking C# vs C++ Performance

2) for C# Only
Compiling .NET to Machine Code
How to Write HighPerformance C# Code | .NET Developer’s Journal (2004)
Performance (C#) (MSDN)
Effective C# – Part I 
How to write friendlier code for the Garbage Collector and to gain performance boost
An in depth look at for loops  and For loop follow up (Disagreeing with Richter?!)

3) example
High-Performance Timer in C# / General / C#   [another]

Posted in Uncategorized | Leave a Comment »

Linq (3)

Posted by steveluo on August 19, 2009

I posted the question and get an answer
Hi I get the followwing direcories by calling GetDirectories()

c:\app\20090331\
c:\app\20090430\
c:\app\20090531\
c:\app\20090630\
c:\app\20090731\
c:\app\20090831\

I want to the directories between 20090531 and 20090731, How can I do it by Linq?
the answer is
var query = directories .Where(x => { return (String.Compare(x, @”c:\app\20090531″) > 0 && String.Compare(x, @”c:\app\20090731″) < 0) ;});

Posted in Uncategorized | Leave a Comment »

What a advanced C# developer should know

Posted by steveluo on July 19, 2009

1.  http://stackoverflow.com/questions/365489/questions-every-net-developer-should-be-able-to-answer
2. http://stackoverflow.com/questions/1099621/what-all-should-an-expert-c-net-wpf-developer-know
3. “What Great .NET Developers Ought To Know”,

Posted in Uncategorized | Leave a Comment »

Linq(2) to DataTable

Posted by steveluo on July 19, 2009

Generally we need get an  initial dataset  from Database by Sql   and then use  linq to filter it again to serve different purposes.   the article show how to create a tableView based on linq:

  • EnumerableRowCollection query   
  •               = from customer in dtCustomer.AsEnumerable()   
  •                 where customer.Field(“State”) == “NJ”  
  •                 select customer;   
  •             DataView njview = query.AsDataView();  

    the chapter Chapter 14 in LinQ in Action gives us the details.  and Other examples on the web and Linq to DataTable  example1 

  • Points to understand Linq:  (from Joseph Rattz’s book)
    1)  linq, a query,  returnes set of objects is called a sequence.  Most linq sequences are of type IEnumerable<T>
    2)  a lambda expression in C# with format:   
             a)
    (param1, param2, …paramN) => expr
             b) 
    (param1, param2, …paramN) =>   {   statement1; statement2; … statementN; return(lambda_expression_return_type); }
           e.g:   
    x => x.Length > 0   could be read as   “input x returns x.Length > 0.”

    Linq Wiki
    get data from Excel by linq

     

     

     

    Posted in Uncategorized | Leave a Comment »

    LINQ

    Posted by steveluo on April 11, 2009

    1) How to use Aggregate functions with LINQ to SQL
    2) http://www.linqpad.net/
    3)  Chasing Tail: C# needs Linq to be (really) functional language

    4 microsoft 101 samples

    5: 7 tricks to simplify your programs with LINQ | Igor Ostrovsky Blogging

    Posted in Uncategorized | Leave a Comment »

    DataTable to Excel

    Posted by steveluo on April 10, 2009

    1) cliperboard
       http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_23003697.html
    2) CSV file
        http://gis.utah.gov/code-c-/c-convert-ado-net-datatable-to-excel-spreadsheet-3
    3) interop

    4)  XML
    ds as new dataset
    ds.tables.add(yourtable)
    ds.writexml(“yourfile”)

    Posted in Uncategorized | Leave a Comment »

    WPF basics

    Posted by steveluo on March 15, 2009

    Dependency Property (Notes from WPF unleashed  p45-57)

    dependency properties add value on top of plain .NET properties:
    . Change notification  — Whenever the value of a dependency property changes, WPF can automatically
                                                     trigger a number of actions depending on the property’s metadata, see trigger
    . Property value inheritance  — flowing of property values down the element tree.
    . Support for multiple providers  — a five-step process  (see p57)

        want the text in each Button from the About dialog in  to turn blue when the mouse pointer hovers over it.
    normal way with WPF trigger
    <Button MouseEnter=”Button_MouseEnter” MouseLeave=”Button_MouseLeave”
                 MinWidth=”75” Margin=”10”>Help</Button>
    <Button MouseEnter=”Button_MouseEnter” MouseLeave=”Button_MouseLeave”
                  MinWidth=”75” Margin=”10”>OK</Button>

    void Button_MouseEnter(object sender, MouseEventArgs e)
    {
            Button b = sender as Button;
            if (b != null)
                  b.Foreground = Brushes.Blue;
    }
    // Restore the foreground to black when the mouse exits the button
    void Button_MouseLeave(object sender, MouseEventArgs e)
    {
           Button b = sender as Button;
           if (b != null)
                  b.Foreground = Brushes.Black;
    }
    <Trigger Property=”IsMouseOver” Value=”True”>
          <Setter Property=”Foreground” Value=”Blue”/>
    </Trigger>

    For example, the data binding system in WPF is rooted in the FrameworkElement.DataContext dependency property.  The value of that property is inherited by all descendant elements. For more see Josh’s blog

    Business objects — without  dependency properties  (see the details )  
    For a business object being bound, there are certain requirements for automatic change notification. There are three approaches you can take:

    • Implement dependency properties in your business object. 
    • Raise an event named <Property Name>Changed. This event must match the property name, and the class must raise the event.
    • Implement the INotifyPropertyChanged in the System.ComponentModel namespace. This interface defines a PropertyChanged event. The business object must fire this event every time any property value changes.

    Posted in Uncategorized | Leave a Comment »

    SAPI

    Posted by steveluo on March 14, 2009

    I ran into speech demo Programming Speech in WPFSpeech Synthesis  which is based on Speech Application Programming Interface or SAPI  SDK  5.3  and found sound quality is not good because Xp default voice engine is  
    Mircrosoft  Sam (you can find what voice engines have been installed on the computer by following Control Panel->Speech->Speech Properties->Text To Speech tab->Voice selection drop down window)
    Try to download Microsoft Anna for my XP.

    from
    SpeechSynthesizer ttsSynth = new SpeechSynthesizer();
     ttsSynth.SelectVoice(“Microsoft Anna”);
    //ttsSynth.Volume =  //ttsSynth.Rate 
     ttsSynth.Speak(“Greetings, my name is ” + ttsSynth.Voice.Name);

    Posted in Uncategorized | Leave a Comment »

    Back to Basics (3)

    Posted by steveluo on March 8, 2009

    Event
    An event is a message sent by an object to signal the occurrence of an action (such as mouse click, or some program logic).
    event sender:      The object that raises the event
    event receiver:   The object that captures the event and responds to it

    A delegate is thus equivalent to a type-safe function pointer or a callback

    Posted in Uncategorized | Leave a Comment »

    Back to Basics (2)

    Posted by steveluo on March 8, 2009

    Properties
    see  MSDN’s Using Properties
    “Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields.”

    a)  Auto-Implemented Properties (C#3.0 and up) :
          “the compiler creates a private, anonymous backing field can only be accessed through the property’s get and set accessors.
          The compiler creates backing fields for each auto-implemented property. The fields are not accessible directly from source” code.
    // Auto-Impl Properties for trivial get and set
        public double TotalPurchases { get; set; }
        public string Name { get; set; }
        public int CustomerID { get; set; }

    b)  Implement an Immutable Class That Has Auto-Implemented 
      “with auto-implemented properties, both a get and set accessor are required. You make the class immutable by declaring the set accessors as private. However, when you declare a private set accessor, you cannot use an object initializer to initialize the property. You must use a constructor or a factory method.”

    Posted in Uncategorized | Leave a Comment »