Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MyNameSpace;
- ...
- global::System.Data
- object->method();
- object->property;
- class::method();
- class::property;
- object.method();
- class.property;
- <?php
- class Circle {
- public $radius;
- public $centerX;
- public $centerY;
- public static $PI = 3.1415;
- public function __construct($r,$x,$y) {
- $this->radius = $r;
- $this->centerX = $x;
- $this->centerY = $y;
- }
- public function getArea() {
- return self::$PI * $this->radius * $this->radius;
- }
- }
- $circle1 = new Circle(10,0,0);
- echo $circle1->getArea() . "<br>n";
- $circle2 = new Circle(15,10,12);
- echo $circle2->getArea() . "<br>n";
- Circle::$PI = 3.14;
- echo $circle1->getArea() . "<br>n";
- echo $circle2->getArea() . "<br>n";
- ?>
- namespace Foo {
- namespace System {
- class DateTime {}
- class Example {
- object Example() {
- return System.DateTime.Now; // Returns Foo.System.DateTime.Now
- return global::System.DateTime.Now; // Returns mscorlib,System.DateTime.Now
- }
- }
- }
- }
- using IOAlias = System.IO;
- IOAlias::StreamReader sr = new StreamReader(path);
- global::System.IO.StreamReader sr = new StreamReader(path);
- public class MyClass { }
- namespace namespaceB
- {
- public class A
- {
- public class MyClass { }
- }
- public class OtherClass
- {
- public A.MyClass MyAClass;
- }
- }
- Explanation
- In the example above, the compiler would always resolve the
- MyAClass to the type namespaceB.A.MyClass.
- If you wanted it to be A.MyClass, there was no way to do it until C# 2.0.
- In C# 2.0, you would use: public class MyOtherClass
- { public global::A.MyClass yAClass; }
- To indicate that you shouldn't use the local namespace scope,
- but rather, the root namespace.
Add Comment
Please, Sign In to add comment