Search This Blog

Thursday, April 23, 2015

LINQ Average excluding or including zeros c#

C# > LINQ > Average


Average computes the average of a sequence of numeric values.

Example


int[] int_array = new int[] { 5, 4, 2, 8, 10, 0 };

// linq average excluding zeros

double avg =
       (from ord in int_array
        where ord > 0
        select ord).Average();  // 5.8

// linq average including zeros 
avg =
       (from ord in int_array
       select ord).Average();    // 4.83





Wednesday, April 8, 2015

UPDATE SQL Server Example

SQL Server > DML > UPDATE

Changes existing data in a table or view.


Example


update
   person
set
   name = 'Bill'
where 
   id = 1



Wednesday, April 1, 2015

Reflection to find all classes implementing interface c#

C# > Reflection Find classes implementing interface

var iTtype = typeof(Interface);
var types = AppDomain.CurrentDomain.GetAssemblies()
           .SelectMany(a => a.GetTypes())
           .Where(t => iTtype.IsAssignableFrom(t));





Telerik GridViewCheckBoxColumn Alignment

Telerik > Windows Forms > RadGridView > GridViewCheckBoxColumn

GridViewCheckBoxColumn displays and allows editing of 

boolean data.

Example

GridViewCheckBoxColumn Alignment


<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsManager}" >
    <telerik:GridViewCheckBoxColumn.CellStyle>
        <Style TargetType="telerik:GridViewCell">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
        </Style>
    </telerik:GridViewCheckBoxColumn.CellStyle>


</telerik:GridViewCheckBoxColumn>




Calculate SQL Server row size for a table

SQL Server > Scripts > Row Size


create table ##RowSize (tableName nvarchar(50), rowSize int)
exec sp_msforeachtable 'INSERT INTO ##RowSize Select ''?'' As tableName, SUM(c.Length) from dbo.SysColumns c where c.id = object_id(''?'') '
select * from ##RowSize order by rowSize  desc
drop table ##RowSize