Tutorial by Examples: class

The <see> tag can be used to link to another class. It contains the cref member which should contain the name of the class that is to be referenced. Visual Studio will provide Intellsense when writing this tag and such references will be processed when renaming the referenced class, too. /// ...
You can use the System.IO.File.ReadAllText function to read the entire contents of a file into a string. string text = System.IO.File.ReadAllText(@"C:\MyFolder\MyTextFile.txt"); You can also read a file as an array of lines using the System.IO.File.ReadAllLines function: string[] line...
The System.IO.StreamWriter class: Implements a TextWriter for writing characters to a stream in a particular encoding. Using the WriteLine method, you can write content line-by-line to a file. Notice the use of the using keyword which makes sure the StreamWriter object is disposed as soon as ...
You can use the System.IO.File.WriteAllText function to write a string to a file. string text = "String that will be stored in the file"; System.IO.File.WriteAllText(@"C:\MyFolder\OutputFile.txt", text); You can also use the System.IO.File.WriteAllLines function which receiv...
Given a String containing the name of a class, it's Class object can be accessed using Class.forName: Class clazz = null; try { clazz = Class.forName("java.lang.Integer"); } catch (ClassNotFoundException ex) { throw new IllegalStateException(ex); } Java SE 1.2 It can be s...
Partial classes provide an ability to split class declaration (usually into separate files). A common problem that can be solved with partial classes is allowing users to modify auto-generated code without fearing that their changes will be overwritten if the code is regenerated. Also multiple devel...
Feature detection of classes can partly be done with the property_exists and method_exists functions. class MyClass { public $public_field; protected $protected_field; private $private_field; static $static_field; const CONSTANT = 0; public function public_function() {...
There are three ways to set the classpath. It can be set using the CLASSPATH environment variable : set CLASSPATH=... # Windows and csh export CLASSPATH=... # Unix ksh/bash It can be set on the command line as follows java -classpath ... javac -classpath ... Note ...
If you want to add all the JARs in directory to the classpath, you can do this concisely using classpath wildcard syntax; for example: someFolder/* This tells the JVM to add all JAR and ZIP files in the someFolder directory to the classpath. This syntax can be used in a -cp argument, a CLASSPA...
The classpath is a sequence of entries which are directory pathnames, JAR or ZIP file pathnames, or JAR / ZIP wildcard specifications. For a classpath specified on the command line (e.g. -classpath) or as an environment variable, the entries must be separated with ; (semicolon) characters on Wi...
Sometimes, just adding all the JARs from a folder isn't enough, for example when you have native code and need to select a subset of JARs. In this case, you need two main() methods. The first one builds a classloader and then uses this classloader to call the second main(). Here is an example which...
When inheriting from any base class, only one partial class needs to have the base class specified. // PartialClass1.cs public partial class PartialClass : BaseClass {} // PartialClass2.cs public partial class PartialClass {} You can specify the same base class in more than one partial clas...
Suppose the following generic interface has been declared: public interface MyGenericInterface<T> { public void foo(T t); } Below are listed the possible ways to implement it. Non-generic class implementation with a specific type Choose a specific type to replace the formal type ...
/** * Load a class by from a ClassNode * * @param cn * ClassNode to load * @return */ public static Class<?> load(ClassNode cn) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); return new ClassDefiner(ClassLoader.getSystemClassLoader()).get(cn....
public static void main(String[] args) throws Exception { File jarFile = new File("Input.jar"); Map<String, ClassNode> nodes = JarUtils.loadClasses(jarFile); Map<String, byte[]> out = JarUtils.loadNonClassEntries(jarFile); Map<String, String> map...
<?php class MyClass { ... } class OtherClass { ... } ?> Any class that has the same name as it's file name will be auto loaded by Silverstripe. OtherClass will be loaded too because it is in a file which is being read. MyPage.php <?php class MyPage_Controller e...
Following the 'Form Request Validation' example, the same Request Class can be used for POST, PUT, PATCH so you do not have to create another class using the same/similar validations. This comes in handy if you have attributes in your table that are unique. /** * Get the validation rules that a...
Anonymous classes were introduced into PHP 7 to enable for quick one-off objects to be easily created. They can take constructor arguments, extend other classes, implement interfaces, and use traits just like normal classes can. In its most basic form, an anonymous class looks like the following: ...
A type class is simply a trait with one or more type parameters: trait Show[A] { def show(a: A): String } Instead of extending a type class, an implicit instance of the type class is provided for each supported type. Placing these implementations in the companion object of the type class all...
Order of class members Class members should be ordered as follows: Fields (in order of public, protected and private) Constructors Factory methods Other Methods (in order of public, protected and private) Ordering fields and methods primarily by their access modifiers or identifier is not ...

Page 12 of 28