0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SwiftとDartの変数、定数宣言、型推論の違い

Posted at

母語がSwiftとなっているので、メモ

SwiftとDart比較

Swift

import Foundation

// 変数の宣言
var myVariable = 42
myVariable = 50

// 定数の宣言
let myConstant = 42

// 型推論による変数の宣言
let inferredInt = 42          // inferredIntはInt型
let inferredDouble = 3.14     // inferredDoubleはDouble型
let inferredString = "Hello"  // inferredStringはString型

// 明示的な型宣言した定数
let explicitInt: Int = 42
let explicitDouble: Double = 3.14
let explicitString: String = "Hello"

// 明示的な型宣言した変数
var name: String = "John"
var age: Int = 30
var isActive: Bool = true


Dart

void main() {
  // 変数の宣言
  var myVariable = 42;
  myVariable = 50;

  // 定数の宣言 (実行時定数)
  final myFinal = 42;

  // 定数の宣言 (コンパイル時定数)
  const myConst = 42;

  // 型推論による変数の宣言
  var inferredInt = 42;          // inferredIntはint型
  var inferredDouble = 3.14;     // inferredDoubleはdouble型
  var inferredString = "Hello";  // inferredStringはString型

  // 明示的な型宣言した定数
  final int explicitInt = 42;
  final double explicitDouble = 3.14;
  final String explicitString = "Hello";
  const String myWord = "Test";

  // 明示的な型宣言した変数
  String name = "John";
  int age = 30;
  bool isActive = true;
}

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?