C# で enum と int 、 string を 相互 に 変換 する 方法

列挙型(enum) → 文字列(string)

var enmVal = Season.Spring;
var strVal = Enum.GetName(typeof(Season), enmVal);

列挙型(enum) → 数値(int)

var enmVal = Season.Autumn | Season.Winter;
var intVal = (int)enmVal;

文字列(string) → 列挙型(enum)

var strVal = "spring, summer";
var enmVal = (Season)Enum.Parse(typeof(Season), strVal, true);

数値(int) → 列挙型(enum)

var intVal = 2;
var enmVal = (Season)Enum.ToObject(typeof(Season), intVal);

C#/VB.netですべての例外をキャッチする

vb.net

Try
    'ファイルを開く
    sr = System.IO.File.OpenText(filePath)
Catch ex As System.IO.FileNotFoundException
    System.Console.WriteLine(ex.Message)
    Return Nothing
Catch ex As System.IO.IOException
    System.Console.WriteLine(ex.Message)
    Return Nothing
Catch ex As System.UnauthorizedAccessException
    System.Console.WriteLine(ex.Message)
    Return Nothing
Catch ex As System.Exception
    'すべての例外をキャッチする
    '例外の説明を表示する
    System.Console.WriteLine(ex.Message)
    Return Nothing
End Try

C#

try
{
    //ファイルを開く
    sr = System.IO.File.OpenText(filePath);
}
catch (System.IO.FileNotFoundException ex)
{
    System.Console.WriteLine(ex.Message);
    return null;
}
catch (System.IO.IOException ex)
{
    System.Console.WriteLine(ex.Message);
    return null;
}
catch (System.UnauthorizedAccessException ex)
{
    System.Console.WriteLine(ex.Message);
    return null;
}
catch (System.Exception ex)
{
    //すべての例外をキャッチする
    //例外の説明を表示する
    System.Console.WriteLine(ex.Message);
    return null;
}

C#でGoogleカレンダーからAPIで日本の祝日を取得する

Newtonsoft.Json 使います。

        public static HashSet<DateTime> GetHolidays(int year)
        {
            var key = "あなたのAPIキー";
            var holidaysId = "japanese__ja@holiday.calendar.google.com";
            var startDate = new DateTime(year, 1, 1).ToString("yyyy-MM-dd") + "T00%3A00%3A00.000Z";
            var endDate = new DateTime(year, 12, 31).ToString("yyyy-MM-dd") + "T00%3A00%3A00.000Z";
            var maxCount = 30;

            var url = $"https://www.googleapis.com/calendar/v3/calendars/{holidaysId}/events?key={key}&timeMin={startDate}&timeMax={endDate}&maxResults={maxCount}&orderBy=startTime&singleEvents=true";
            var client = new WebClient() { Encoding = System.Text.Encoding.UTF8 };
            var json = client.DownloadString(url);
            client.Dispose();

            var o = Newtonsoft.Json.Linq.JObject.Parse(json);
            var days = o["items"].Select(i => DateTime.Parse(i["start"]["date"].ToString()));
            return new HashSet<DateTime>(days);
        }