This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
public virtual void DoWork5(int num1, int num2 = 0){
}
PropertiesProperties
● Get● Set● Indexer
public int total{
get { return price * qty; }}
Public string FullName{
get { return firstname + lastname };set{
var strings = value.split(' ');firstname = strings[0];lastname = strings[1];
}}
StructsStructs
● useful for small data structures● No null! use with Nullable types
public struct RGB{
public int red;public int Green;public int blue;
}
InterfaceInterface
● An interface contains only the signatures of methods, delegates or events.
public interface IStatus{
char Status { get; set; } bool Equal(IStatus other);
}
Casting and Type Conversions
● Implicit Conversions● Explicit Conversions● Is, as, typeof
GenericGeneric
● Use generic types to maximize code reuse, type safety, and performance.
● The most common use of generics is to create collection classes.
public class Stack<T>public class Stack<T>{{ T[] m_Items; T[] m_Items; public void Push(T item)public void Push(T item) {...}{...} public T Pop()public T Pop() {...}{...}}}Stack<int> stack = new Stack<int>();Stack<int> stack = new Stack<int>();stack.Push(1);stack.Push(1);stack.Push(2);stack.Push(2);int number = stack.Pop();int number = stack.Pop();
EnumEnum
● An enumeration type (also named an enumeration or an enum) provides an efficient way to define a set of named integral constants that may be assigned to a variable
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
Delegates & EventsDelegates & Events
● Delegatepublic delegate int Calculate (int value1, int value2);
void HandleCustomEvent(object sender, CustomEventArgs a) { // Do something useful here. }
AttributeAttribute
● Attributes provide a powerful method of associating declarative information with C# code (types, methods, properties, and so forth). Once associated with a program entity, the attribute can be queried at run time using a technique called Reflection.
– A non-prime attribute is an attribute that does not occur in any candidate key. Employee Address would be a non-prime attribute in the "Employees' Skills" table.
● Prime attribute
– A prime attribute, conversely, is an attribute that does occur in some candidate key.
Normal formsNormal forms
First normal form (1NF)First normal form (1NF)
● First normal form (1NF) is a property of a relation in a relational database. A relation is in first normal form if the domain of each attribute contains only atomic values, and the value of each attribute contains only a single value from that domain.
{Court, Start Time}{Court, End Time}{Rate Type, Start Time}{Rate Type, End Time}{Court, Start Time, End Time}{Rate Type, Start Time, End Time}{Court, Rate Type, Start Time}{Court, Rate Type, End Time}
● IN To specify multiple possible values for a column
Data query
● Select – as, subquery● From – join, subquery● Where – In, Exists, subquery● Group by● Having● Order by - asc, desc, null first, null last● Offset, Limit
Aggregate Functions
● Count● Max, Min, Avg, Sum● First, Last
Data manipulationData manipulation
● Insertinsert into tbl(col1, col2) values(...)insert into tbl(col1, col2) select … from … where ...
● Updateupdate tbl set col1 = val1, col2 = val2 where col3 = val3
● Deletedelete from tbl where col1 = val1
● Merge (Upsert)
Data definitionData definition
● Create– Create table, create index
● Drop– Drop table, drop index
● Alter– Alter table, alter index
ConstraintConstraint
● Not null● Unique● Primary key – auto increment● Foreign key
WITH regional_sales AS ( SELECT region, SUM(amount) AS total_sales FROM orders GROUP BY region ), top_regions AS ( SELECT region FROM regional_sales WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales) )SELECT region, product, SUM(quantity) AS product_units, SUM(amount) AS product_salesFROM ordersWHERE region IN (SELECT region FROM top_regions)GROUP BY region, product;
// Defines a delegate that takes an int and returns an intpublic delegate int ChangeInt(int x); // Define a method to which the delegate can pointstatic public int DoubleIt(int x){ return x * 2;}
ChangeInt myDelegate = new ChangeInt(DelegateSample.DoubleIt);Console.WriteLine("{0}", myDelegate(5));
ChangeInt myDelegate = new ChangeInt( delegate(int x) { return x * 2; });Console.WriteLine("{0}", myDelegate(5));
Lambda Expression
ChangeInt myDelegate = x => x * 2;Console.WriteLine("{0}", myDelegate(5));
ChangeInt myDelegate = (int x) => x * 2;Console.WriteLine("{0}", myDelegate(5));
// Defines a delegate that takes two ints and returns an intpublic delegate int MultiplyInts(int arg, int arg2);
MultiplyInts myDelegate = (a, b) => a * b;Console.WriteLine("{0}", myDelegate(5, 2));
Statement Lambda Expression
int[] source = new[] { 3, 8, 4, 6, 1, 7, 9, 2, 4, 8 }; foreach (int i in source.Where( x => { if (x <= 3) return true; else if (x >= 7) return true; return false; } )) Console.WriteLine(i);
Lambda Expressions that Return Void
// Defines a delegate that takes a string and returns voidpublic delegate void OutputToConsole(string arg); static void Main(string[] args){ OutputToConsole o = a => { Console.WriteLine(a); }; o("Hello, World");}
// Defines a delegate that takes no arguments and returns voidpublic delegate void OutputHelloToConsole(); static void Main(string[] args){ OutputHelloToConsole o = () => { Console.WriteLine("Hello, World"); }; o();}
The Func Delegate Types● public delegate TR Func<TR>();
● public delegate TR Func<T0, TR>(T0 a0);
● public delegate TR Func<T0, T1, TR>(T0 a0, T1 a1);
from v_user_realtime_9 urv left outer join nt_z_box_data bd on b.boxid = bd.boxid and b.latest_box_data_boxdatadate = bd.date left outer join nt_cellsite c on bd.cellsite_id = c.id
where urv.username = :username and date = :startDate
● Do Not Assume That Parallel Is Always Faster● Avoid Writing to Shared Memory Locations● Avoid Over-Parallelization● Avoid Calls to Non-Thread-Safe Methods● Limit Calls to Thread-Safe Methods● Be Aware of Thread Affinity Issues
Monitoring tools
● Event viewer● Performance counter● DB log file
Principle of software development
● D.R.Y. - Don't Repeat Yourself● Separation of concerns (SoC)● SOLID● KISS● GRASP● You aren't gonna need it (YAGNI)