【C#】intからstring変換(数値から文字列に変換する) リンクを取得 Facebook × Pinterest メール 他のアプリ 2月 23, 2023 C#で整数を文字列に変換するには、以下の2つの主要な方法があります。// ToStringでそのまま変換するint num = 123;string str = num.ToString();// Fromatを使用して変換する// 例)今日の温度は{0}度です。int num = 123;string str = String.Format("{0}", num); リンクを取得 Facebook × Pinterest メール 他のアプリ コメント
【C#】SharpZipLibの解凍と圧縮について 2月 22, 2023 SharpZipLibは、C#でZIPアーカイブを操作するためのオープンソースのライブラリです。以下は、SharpZipLibを使用してZIPアーカイブを圧縮する方法と、解凍する方法の例です。 圧縮する場合の例: using ICSharpCode . SharpZipLib . Zip ; // Zipファイルに圧縮するフォルダパス string directoryPath = @"C:\example\directory" ; // Zipファイルの保存先パス string zipFilePath = @"C:\example\archive.zip" ; // Zipファイルを作成し、フォルダ内のファイルを圧縮する using ( ZipOutputStream zipStream = new ZipOutputStream ( File . Create ( zipFilePath ))) { // 圧縮レベルを設定する zipStream . SetLevel (5); // フォルダ内のファイルを取得する string [] files = Directory . GetFiles ( directoryPath , "*" , SearchOption . AllDirectories ); // ファイルを圧縮してZipファイルに追加する foreach ( string file in files ) { ZipEntry entry = new ZipEntry ( Path . GetFileName ( file )); entry . DateTime = DateTime . Now ; zipStream . PutNextEntry ( entry ); using ( FileStr... 続きを読む
【C#】簡易電卓 2月 22, 2023 C#言語で作成した電卓プログラムの例を示します。このプログラムでは、コンソール上で四則演算ができるシンプルな電卓を実装しています。 using System ; class Program { static void Main ( string [] args) { Console . WriteLine ( "シンプル電卓" ); while ( true ) { Console . Write ( "式を入力してください(例:1 + 2):" ); string input = Console . ReadLine (); string [] parts = input . Split ( ' ' ); if ( parts . Length != 3 ) { Console . WriteLine ( "不正な入力です。" ); continue ; } double num1, num2; if ( ! double . TryParse ( parts [ 0 ], out num1 ) || ! double . TryParse ( parts [ 2 ], out num2... 続きを読む
【C#】うるう年判定 2月 22, 2023 このプログラムは、ユーザーに年を入力してもらい、その年がうるう年かどうかを判定します。if文を使って、以下の条件を満たす場合には「〇〇年はうるう年です。」と表示し、それ以外の場合には「〇〇年はうるう年ではありません。」と表示します。 西暦年号が4で割り切れる年は閏年。 ただし100で割り切れる年は平年。 ただし400で割り切れる年は閏年。 class Program { static void Main ( string [] args) { Console . Write ( "年を入力してください:" ); int year = int . Parse ( Console . ReadLine ()); if (( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 ) { Console . WriteLine ( "{0}年はうるう年です。" , year ); } else { Console . WriteLine ( "{0}年はうるう年ではありません。" , year ); } } } 続きを読む
コメント
コメントを投稿