Search This Blog
Tuesday, May 19, 2015
Monday, May 18, 2015
Subtract SQL Server example
SQL Server > Operators > Subtract
- Operator (minus) subtracts two numbers or a number (in days) from date.
Example
1. Subtracts values from 2 numeric columns
create table #test(value int, fee int)
insert into #test(value, fee) values (500,50),(100,10)
select
value - fee as 'diff'
from
#test
drop table #test
Result
diff
450
90
2. Subtracts from date
SELECT getdate() - 1 AS 'Subtract Date';
- Operator (minus) subtracts two numbers or a number (in days) from date.
Example
1. Subtracts values from 2 numeric columns
create table #test(value int, fee int)
insert into #test(value, fee) values (500,50),(100,10)
select
value - fee as 'diff'
from
#test
drop table #test
Result
diff
450
90
2. Subtracts from date
SELECT getdate() - 1 AS 'Subtract Date';
Etichete:
SQL Server
C# unit test using Moq verify property has been set
C# > Unit test > Moq > Verify property has been set
SetupSet : Specifies a setup on the mocked type for a call to a property setter.
VerifySet : Verifies that a property has been set on the mock, regardless of its value.
Example
using System;
namespace UnitTestProject1
{
public interface Interface1
{
int Id { get; set; }
}
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var mocker = new Mock<Interface1>();
mocker.SetupSet(x => x.Id = 1);
mocker.Object.Id = 1;
mocker.VerifySet(x => x.Id);
}
}
}
Etichete:
c#,
Unit tests
Friday, May 15, 2015
Convert string to date C# example
C# > System Namespace > DateTime > Parse
Parse converts string to a date.
Example
Parse converts string to a date.
Example
string value = "5/15/2015";
var dte = DateTime.Parse(value,
CultureInfo.InvariantCulture); // {5/15/2015 12:00:00 AM}
Etichete:
c#
Thursday, May 14, 2015
Find last row Telerik RadGridView
Telerik > RadGridView > Find last rowGridViewRowInfo lastRow = radGridView.Rows[radGridView.Rows.Count - 1]; lastRow.IsSelected = true;
Wednesday, May 13, 2015
C# Generic Interface Example
C# > Generics > Generic Interface
Example
Example
class Serializer1 { public string Name { get; set; } };
class Serializer2 { public string Name { get; set; } };
interface GenericSerializer <T>
{
string Name(T tValue);
}
class Serializer<T>: GenericSerializer<T>
{
public string Name(T tValue)
{
var prop = tValue.GetType().GetProperty("Name");
return prop.GetValue(tValue, null) as string;
}
}
Serializer1 s1 = new Serializer1() { Name = "Serializer1" };
Serializer2 s2 = new Serializer2() { Name = "Serializer2" };
Serializer<Serializer1> serializer1 = new Serializer<Serializer1>();
string name1 = serializer1.Name(s1);
Serializer<Serializer2> serializer2 = new Serializer<Serializer2>();
string name2 = serializer2.Name(s2);
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
// linq average including zeros
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
avg =
(from ord in int_array
select ord).Average(); // 4.83
Subscribe to:
Comments (Atom)