This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private String getParameters<T>(T obj) | |
| { | |
| StringBuilder parameters = new StringBuilder(); | |
| var properties = typeof(T).GetProperties(); | |
| foreach(Property property in properties) | |
| { | |
| if(property.GetValue(obj, null) != null) | |
| { | |
| String propertyValue = property.GetValue(obj, null).ToString(); | |
| String propertyName = property.Name.ToString(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @TopID_in int -- The top level we want to resolve children for | |
| SELECT @TopID_in = -- ID of parent node | |
| ;WITH HierarchyCTE(ID, ParentID) AS | |
| ( | |
| SELECT Id, ParentId | |
| FROM Categories | |
| WHERE Id = @TopID_in | |
| UNION ALL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @ID int | |
| SET @ID = -- ID of child node | |
| ;WITH cte AS( | |
| SELECT ParentId AS pid, 1 AS lvl | |
| FROM Categories | |
| WHERE Id = @ID | |
| UNION ALL | |
| SELECT a.ParentId as pid, lvl+1 | |
| FROM Categories a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT '2015-01-' | |
| + RIGHT('00' + CAST( | |
| ROUND(((28 - 1 -1) * RAND() + 1), 0) | |
| AS varchar), 2) | |
| + ' ' | |
| + RIGHT('00' + CAST( | |
| ROUND(((24 - 0 -0) * RAND() + 0), 0) | |
| AS varchar), 2) -- Hour | |
| + ':' | |
| + RIGHT('00' + CAST( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int[] array = {2, 3, 5, 5, 7, 11, 11, 11, 13}; | |
| int originalNumber = array[0]; | |
| for (int i = 1; i < array.Length; i++) | |
| { | |
| if (array[i] == originalNumber) | |
| { | |
| array[i] = 0; | |
| } | |
| else | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int removeDuplicates(int[] A) { | |
| if (A.length == 0) { | |
| return 0; | |
| } | |
| int writeIndex = 0; | |
| for (int i = 1; i < A.length; ++i) { | |
| if (A[writeIndex] != A[i]) { | |
| A[++writeIndex] = A[i]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int[] removeDuplicates(int[] A) | |
| { | |
| int writeIndex = 0; | |
| for (int i = 1; i < A.Length; i++) | |
| { | |
| if (A[writeIndex] != A[i]) | |
| { | |
| writeIndex++; | |
| A[writeIndex] = A[i]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static List<int> returnPrimeNumbersToN(int n) | |
| { | |
| List<int> primeNumbers = new List<int>(); | |
| primeNumbers.Add(2); | |
| primeNumbers.Add(3); | |
| for (int i = 5; i <= n; i += 2) | |
| { | |
| bool test = true; | |
| int sqrt = Convert.ToInt32(Math.Sqrt(i)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static List<int> returnPrimeNumbersToN(int n) | |
| { | |
| List<int> primeNumbers = new List<int>(); | |
| // populate list | |
| for (int i = 2; i <= n; i++) | |
| { | |
| primeNumbers.Add(i); | |
| } |
OlderNewer