Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ チャレンジ:クラスの作成 | オブジェクト指向プログラミング(OOP)イントロダクション
C#オブジェクト指向構造

bookチャレンジ:クラスの作成

メニューを表示するにはスワイプしてください

Employeeというクラスを作成し、従業員の名前、年齢、給与を格納できるコードの作成。年齢は整数値、給与は倍精度浮動小数点数で保持。

index.cs

index.cs

copy
12345678910111213141516171819
using System; // Write class code below this line // Write class code above this line public class ConsoleApp { public static void Main(string[] args) { Employee e1 = new Employee(); e1.name = "Jenny"; e1.age = 32; e1.salary = 70000.0; Console.WriteLine($"{e1.name} is {e1.age} years old and she earns ${e1.salary} per year."); } }
  1. クラス宣言の構文は構造体宣言と非常によく似ているが、Structキーワードの代わりにClassを使用。
  2. コードがコンパイルできない場合は、クラス内の各フィールドの前にpublicキーワードを付けているか確認。
index.cs

index.cs

copy
1234567891011121314151617181920212223
using System; // Write class code below this line class Employee { public string name; public int age; public double salary; } // Write class code above this line public class ConsoleApp { public static void Main(string[] args) { Employee e1 = new Employee(); e1.name = "Jenny"; e1.age = 32; e1.salary = 70000.0; Console.WriteLine($"{e1.name} is {e1.age} years old and she earns ${e1.salary} per year."); } }
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  3

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 3.  3
some-alt