Tutorial by Examples: d

var person = new Person { Address = null; }; var city = person.Address.City; //throws a NullReferenceException var nullableCity = person.Address?.City; //returns the value of null This effect can be chained together: var person = new Person { Address = new Address { ...
You can use Scanner to read all of the text in the input as a String, by using \Z (entire input) as the delimiter. For example, this can be used to read all text in a text file in one line: String content = new Scanner(new File("filename")).useDelimiter("\\Z").next(); System.o...
You can use custom delimiters (regular expressions) with Scanner, with .useDelimiter(","), to determine how the input is read. This works similarly to String.split(...). For example, you can use Scanner to read from a list of comma separated values in a String: Scanner scanner = null; tr...
This is placed in a Windows Forms event handler var nameList = new BindingList<string>(); ComboBox1.DataSource = nameList; for(long i = 0; i < 10000; i++ ) { nameList.AddRange(new [] {"Alice", "Bob", "Carol" }); } This takes a long time to execute,...
BindingList<string> listOfUIItems = new BindingList<string>(); listOfUIItems.Add("Alice"); listOfUIItems.Add("Bob");
Overview In this example 2 clients send information to each other through a server. One client sends the server a number which is relayed to the second client. The second client halves the number and sends it back to the first client through the server. The first client does the same. The server st...
Parentheses are now forbidden around named parameters. The following compiles in C#5, but not C#6 5.0 Console.WriteLine((value: 23)); Operands of is and as are no longer allowed to be method groups. The following compiles in C#5, but not C#6 5.0 var result = "".Any is byte; T...
The JavaScriptSerializer.Deserialize<T>(input) method attempts to deserialize a string of valid JSON into an object of the specified type <T>, using the default mappings natively supported by JavaScriptSerializer. using System.Collections; using System.Web.Script.Serialization; // ....
internal class Sequence{ public string Name; public List<int> Numbers; } // ... string rawJSON = "{\"Name\":\"Fibonacci Sequence\",\"Numbers\":[0, 1, 1, 2, 3, 5, 8, 13]}"; Sequence sequence = JsonConvert.DeserializeObject<Seque...
Optional<String> optionalWithValue = Optional.of("foo"); optionalWithValue.ifPresent(System.out::println);//Prints "foo". Optional<String> emptyOptional = Optional.empty(); emptyOptional.ifPresent(System.out::println);//Does nothing.
DOM stands for Document Object Model. It is an object-oriented representation of structured documents like XML and HTML. Setting the textContent property of an Element is one way to output text on a web page. For example, consider the following HTML tag: <p id="paragraph"></p&g...
There are many ways to create arrays. The most common are to use array literals, or the Array constructor: var arr = [1, 2, 3, 4]; var arr2 = new Array(1, 2, 3, 4); If the Array constructor is used with no arguments, an empty array is created. var arr3 = new Array(); results in: [] Note...
Spread operator 6 With ES6, you can use spreads to separate individual elements into a comma-separated syntax: let arr = [1, 2, 3, ...[4, 5, 6]]; // [1, 2, 3, 4, 5, 6] // in ES < 6, the operations above are equivalent to arr = [1, 2, 3]; arr.push(4, 5, 6); The spread operator also act...
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...
Start by defining a Foo function that we'll use as a constructor. function Foo (){} By editing Foo.prototype, we can define properties and methods that will be shared by all instances of Foo. Foo.prototype.bar = function() { return 'I am bar'; }; We can then create an instance using the ...
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) { //parse the response in xhttp.responseText; } }; xhttp.open("GET", "ajax_info.txt", true); xhttp.send(...
Python is a widely used high-level programming language for general-purpose programming, created by Guido van Rossum and first released in 1991. Python features a dynamic type system and automatic memory management and supports multiple programming paradigms, including object-oriented, imperative, f...
echo and print are language constructs, not functions. This means that they don't require parentheses around the argument like a function does (although one can always add parentheses around almost any PHP expression and thus echo("test") won't do any harm either). They output the string r...
Unlike in languages like Python, static properties of the constructor function are not inherited to instances. Instances only inherit from their prototype, which inherits from the parent type's prototype. Static properties are never inherited. function Foo() {}; Foo.style = 'bold'; var foo = ne...
A dictionary comprehension is similar to a list comprehension except that it produces a dictionary object instead of a list. A basic example: Python 2.x2.7 {x: x * x for x in (1, 2, 3, 4)} # Out: {1: 1, 2: 4, 3: 9, 4: 16} which is just another way of writing: dict((x, x * x) for x in (1, 2...

Page 13 of 691