6
4

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.

【C#】intをenumにキャストする方法

Posted at

今回も備忘録投稿
「intをenumにキャストして」なんて言われて、なんだそりゃ?ってなってたところ先輩が参考になるサイトを教えてくれました。

参考にさせていただいたサイト↓
https://garafu.blogspot.jp/2015/07/c-enum.html
こういうのって忘れた頃にまた使うんですよね。

##intをenumに変換

animal.cs
public enum animal
{
   cat,
   dog,
   rabbit,
}

var intVal = 2;
var enmVal = (animal)Enum.ToObject(typeof(animal), intVal);
6
4
1

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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?