0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

csharp > Null許容型 / Nullable<T>構造体 > HasValue / Value

Last updated at Posted at 2015-10-11

引用: 即効入門 C#プログラミング すぐに現場で使える知識 by 中 博俊さんら
11.1 Null許容型の利用

HasValue : 有効な値を持っている (nullでない)場合にtrueを返す
Value : 値を返す.

サンプルコードを作ってみた
http://ideone.com/vk38Qi

using System;

public class Test
{
	public static void Main()
	{
		int? x = 1;
		int? y = null;
		
		Console.WriteLine(x.HasValue);
		Console.WriteLine(x.Value);
		Console.WriteLine(y.HasValue);
		Console.WriteLine(y.Value);
	}
}
結果
Runtime error	time: 0.06 memory: 26960 signal:-1
True
1
False

https://msdn.microsoft.com/ja-jp/library/1t3y8s4s.aspx
https://msdn.microsoft.com/en-us//library/1t3y8s4s.aspx

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?