Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MightConst - Runtime Constwrapper Value (C#)
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 //orrz using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { /// Runtime 'pseudo-constant' value representation [Serializable()] public class MightConst<T> { private bool constant; private T v; /// Get the contained value public static implicit operator T(MightConst<T> v) { return v.v; } /// Try to assign a new value /// \param v the new value to assign /// \return true if value has been assigned public bool assign(T v) { if (!this.constant) { this.v = v; } return !this.constant; } /// Create new MightConst /// \param v the value /// \param initial constness public MightConst(T v, bool constant) { this.v = v; this.constant = constant; } /// Change the 'constness' of the value /// \param constness to use public void setConstant(bool constant) { this.constant = constant; } } public class Program { public static void Main(string[] args) { var val = new MightConst<double>(3.2, true); Console.WriteLine(val); val.assign(20.0); // won't change since 'const' flag is set Console.WriteLine(val); val.setConstant(false); val.assign(20.0); // will change since 'const' flag is no longer set Console.WriteLine(val); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,14 sec, absolute running time: 0,09 sec, cpu time: 0,09 sec, average memory usage: 15 Mb, average nr of threads: 3
edit mode
|
history
|
discussion
3,2 3,2 20