Tutorial by Examples: du

Simple usage Dapper fully supports stored procs: var user = conn.Query<User>("spGetUser", new { Id = 1 }, commandType: CommandType.StoredProcedure) .SingleOrDefault(); Input, Output and Return parameters If you want something more fancy...
string requestUri = "http://www.example.com"; string requestBodyString = "Request body string."; string contentType = "text/plain"; string requestMethod = "POST"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri) { Method = reque...
string requestUri = "http://www.example.com"; string requestBodyString = "Request body string."; string contentType = "text/plain"; string requestMethod = "POST"; byte[] responseBody; byte[] requestBodyBytes = Encoding.UTF8.GetBytes(requestBodyS...
HttpClient is available through NuGet: Microsoft HTTP Client Libraries. string requestUri = "http://www.example.com"; string requestBodyString = "Request body string."; string contentType = "text/plain"; string requestMethod = "POST"; var request = new ...
Visual Studio helps manage user and application settings. Using this approach has these benefits over using the appSettings section of the configuration file. Settings can be made strongly typed. Any type which can be serialized can be used for a settings value. Application settings can be...
var collection = new BlockingCollection<int>(5); var random = new Random(); var producerTask = Task.Run(() => { for(int item=1; item<=10; item++) { collection.Add(item); Console.WriteLine("Produced: " + item); Thread.Sleep(random.Next(1...
The following examples will not compile: string s = "\c"; char c = '\c'; Instead, they will produce the error Unrecognized escape sequence at compile time.
Product flavors are defined in the build.gradle file inside the android { ... } block as seen below. ... android { ... productFlavors { free { applicationId "com.example.app.free" versionName "1.0-free" } paid { ...
Dependencies can be added for a specific product flavor, similar to how they can be added for specific build configurations. For this example, assume that we have already defined two product flavors called free and paid (more on defining flavors here). We can then add the AdMob dependency for the ...
Resources can be added for a specific product flavor. For this example, assume that we have already defined two product flavors called free and paid. In order to add product flavor-specific resources, we create additional resource folders alongside the main/res folder, which we can then add resourc...
The ScheduledExecutorService class provides a methods for scheduling single or repeated tasks in a number of ways. The following code sample assume that pool has been declared and initialized as follows: ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); In addition to the nor...
Since Java 6, the recommended way to access an SQL-based database in Java is via the JDBC(Java DataBase Connectivity) API. This API comes in two packagages: java.sql and javax.sql. JDBC defines database interactions in terms of Connections and Drivers. A Driver interacts with the database, and pr...
Enum can be considered to be syntax sugar for a sealed class that is instantiated only a number of times known at compile-time to define a set of constants. A simple enum to list the different seasons would be declared as follows: public enum Season { WINTER, SPRING, SUMMER, FA...
A simple example of producer-consumer problem solution. Notice that JDK classes (AtomicBoolean and BlockingQueue) are used for synchronization, which reduces the chance of creating an invalid solution. Consult Javadoc for various types of BlockingQueue; choosing different implementation may drastica...
In JavaScript, functions may be anonymously defined using the "arrow" (=>) syntax, which is sometimes referred to as a lambda expression due to Common Lisp similarities. The simplest form of an arrow function has its arguments on the left side of => and the return value on the right...
The remainder / modulus operator (%) returns the remainder after (integer) division. console.log( 42 % 10); // 2 console.log( 42 % -10); // 2 console.log(-42 % 10); // -2 console.log(-42 % -10); // -2 console.log(-40 % 10); // -0 console.log( 40 % 10); // 0 This operator returns th...
A Promise object represents an operation which has produced or will eventually produce a value. Promises provide a robust way to wrap the (possibly pending) result of asynchronous work, mitigating the problem of deeply nested callbacks (known as "callback hell"). States and control flow ...
import random randint() Returns a random integer between x and y (inclusive): random.randint(x, y) For example getting a random number between 1 and 8: random.randint(1, 8) # Out: 8 randrange() random.randrange has the same syntax as range and unlike random.randint, the last value is no...
Setting a specific Seed will create a fixed random-number series: random.seed(5) # Create a fixed state print(random.randrange(0, 10)) # Get a random integer between 0 and 9 # Out: 9 print(random.randrange(0, 10)) # Out: 4 Resetting the seed will create the same &qu...
Use the import statement: >>> import random >>> print(random.randint(1, 10)) 4 import module will import a module and then allow you to reference its objects -- values, functions and classes, for example -- using the module.name syntax. In the above example, the random module...

Page 1 of 47