Tutorial by Examples: c

type Person = { Age : int PassedDriversTest : bool } let someone = { Age = 19; PassedDriversTest = true } match someone.PassedDriversTest with | true when someone.Age >= 16 -> printfn "congrats" | true -> printfn "wait until you are 16" | false -> p...
>>> code = """for i in range(5):\n print('Hello world!')""" >>> exec(code) Hello world! Hello world! Hello world! Hello world! Hello world!
compile built-in function can be used to precompile an expression to a code object; this code object can then be passed to eval. This will speed up the repeated executions of the evaluated code. The 3rd parameter to compile needs to be the string 'eval'. >>> code = compile('a * b + c', '&l...
>>> variables = {'a': 6, 'b': 7} >>> eval('a * b', globals=variables) 42 As a plus, with this the code cannot accidentally refer to the names defined outside: >>> eval('variables') {'a': 6, 'b': 7} >>> eval('variables', globals=variables) Traceback (most ...
As the static keyword is used for accessing fields and methods without an instantiated class, it can be used to declare constants for use in other classes. These variables will remain constant across every instantiation of the class. By convention, static variables are always ALL_CAPS and use unders...
Static gives a method or variable storage that is not allocated for each instance of the class. Rather, the static variable is shared among all class members. Incidentally, trying to treat the static variable like a member of the class instance will result in a warning: public class Apple { pu...
It is possible to create a QtQuick view directly from C++ and to expose to QML C++ defined properties. In the code below the C++ program creates a QtQuick view and exposes to QML the height and width of the view as properties. main.cpp #include <QApplication> #include <QQmlContext> #...
If you want to mock AR that doesn't try to connect to database you can do it in the following way (if using PHPUnit): $post = $this->getMockBuilder('\app\model\Post') ->setMethods(['save', 'attributes']) ->getMock(); $post->method('save')->willReturn(true); $post->meth...
The Application directive defines application-specific attributes. It is provided at the top of the global.aspx file. The basic syntax of Application directive is: <%@ Application Language="C#" %> The attributes of the Application directive are: AttributesDescriptionInheritsThe...
The control directive is used with the user controls and appears in the user control (.ascx) files. The basic syntax of Control directive is: <%@ Control Language="C#" EnableViewState="false" %> The attributes of the Control directive are: AttributesDescriptionAutoEv...
The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface. The basic syntax for implements directive is: <%@ Implements Interface="interface_name" %>
The Master directive specifies a page file as being the mater page. The basic syntax of sample MasterPage directive is: <%@ MasterPage Language="C#" AutoEventWireup="true" CodeFile="SiteMater.master.cs" Inherits="SiteMaster" %>
The Import directive imports a namespace into a web page, user control page of application. If the Import directive is specified in the global.asax file, then it is applied to the entire application. If it is in a page of user control page, then it is applied to that page or control. The basic synt...
The MasterType directive assigns a class name to the Master property of a page, to make it strongly typed. The basic syntax of MasterType directive is: <%@ MasterType attribute="value"[attribute="value" ...] %>
The Page directive defines the attributes specific to the page file for the page parser and the compiler. The basic syntax of Page directive is: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Trace="tr...
The OutputCache directive controls the output caching policies of a web page or a user control. The basic syntax of OutputCache directive is: <%@ OutputCache Duration="15" VaryByParam="None" %>
This example show how you can check if a service already exists (i.e., is installed on the machine) or not. This code requires only the lowest privileges necessary, so each process can perform the check, no matter what level of security it is running at. #define UNICODE #define _UNICODE #include ...
IList<T> is never a subtype of a different IList<T1>. IList is invariant in its type parameter. class Animal { /* ... */ } class Dog : Animal { /* ... */ } IList<Dog> dogs = new List<Dog>(); IList<Animal> animals = dogs; // type error There is no subtype relat...
To add annotations, hints, or exclude some code from being executed JavaScript provides two ways of commenting code lines Single line Comment // Everything after the // until the end of the line is excluded from execution. function elementAt( event ) { // Gets the element from Event coordinate...
By default, Django renders ForeignKey fields as a <select> input. This can cause pages to be load really slowly if you have thousands or tens of thousand entries in the referenced table. And even if you have only hundreds of entries, it is quite uncomfortable to look for a particular entry amo...

Page 172 of 826