| Value type | Default value |
|---|---|
false
| |
0
| |
'\0'
| |
0.0M
| |
0.0D
| |
The value produced by the expression (E)0, where E is the enum identifier.
| |
0.0F
| |
0
| |
0L
| |
0
| |
0
| |
The value produced by setting all value-type fields to their default values and all reference-type fields to null.
| |
0
| |
0
| |
0
|
Documenting transition of life. From a student, to a worker. What had to be learned, and what had to be unlearned. An insight into one of the biggest changes.
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Wednesday, March 28, 2012
Default Values C#
Whenever you create a value type in C#, it always has to have a default value. Following is a quick reference list of what these defaults are, as taken from MSDN.
Sunday, March 25, 2012
C# and ??
In C#, one can meet the operator made up of two question marks. This is known as the null-coalescing operator, and is used to check if a variable is null. It works as follows.
The beauty of it is that it is transitive, so one can write var a = b ?? c ?? d ?? e;
myClass classInstance = gameObject.GetComponent("myClass.cs") as
myClass;
myClass newVar = classInstance ??
new myClass ();
The second line simply checks if classInstance is null. If it is, it will return a new instance of new myClass(); Else, it will return the classInstance itself. These lines are equivalent to the following:
myClass
classInstance = gameObject.GetComponent("
myClass.cs ") as myClass ;
myClass newVar =
new myClass ();
if (
classInstance == null)
{
newVar = new myClass ();
}
else
{
newVar =
classInstance ;
}
The beauty of it is that it is transitive, so one can write var a = b ?? c ?? d ?? e;
Monday, March 19, 2012
Use C# as REPL
As a developer, sometimes we want to try something out quickly, to see if our idea works as a proof of concept. In the .Net environment this leads many times to many solutions on the desktop named ConsoleApplication1 and ConsoleApplication2, or WinformApplication1, with a form containing only one big button with the text Run! on it.
It is much more convenient to have something like Python has, where one can simply insert the code one line at a time, and see what the output is. This is known as REPL, which stands for Read-Eval-Print-Loop.
There are two ways which I know of how this can be achieved.
The first one is by means of PowerShell. This gives you the option of typing in C# code, and getting results immediately. The problem with this approach is that the code can loook quite different, where DateTime.Now can become [DateTime]::Now.
The second way is by making use of the wonderful tool which is part of the Mono Project. Mono is an open source implementation of the .Net framework, and it can run on multiple operating systems.
This tool, called GSharp, can be found in the Mono Command Prompt. Simply type in csharp, and you are good to go. Typing in DateTime.Now, now works.
It is much more convenient to have something like Python has, where one can simply insert the code one line at a time, and see what the output is. This is known as REPL, which stands for Read-Eval-Print-Loop.
There are two ways which I know of how this can be achieved.
The first one is by means of PowerShell. This gives you the option of typing in C# code, and getting results immediately. The problem with this approach is that the code can loook quite different, where DateTime.Now can become [DateTime]::Now.
The second way is by making use of the wonderful tool which is part of the Mono Project. Mono is an open source implementation of the .Net framework, and it can run on multiple operating systems.
This tool, called GSharp, can be found in the Mono Command Prompt. Simply type in csharp, and you are good to go. Typing in DateTime.Now, now works.
Subscribe to:
Posts (Atom)

