第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

C#vs Java Enum(適用于C#的新手)

C#vs Java Enum(適用于C#的新手)

回首憶惘然 2019-08-15 14:23:05
C#vs Java Enum(適用于C#的新手)我已經(jīng)用Java編程了一段時(shí)間,只是投入了一個(gè)完全用C#編寫的項(xiàng)目。我正試圖加快C#的速度,并注意到在我的新項(xiàng)目中幾個(gè)地方使用的枚舉,但乍一看,C#的枚舉似乎比Java 1.5+實(shí)現(xiàn)更簡(jiǎn)單。任何人都可以枚舉C#和Java枚舉之間的差異,以及如何克服這些差異?(我不想開始語言火焰戰(zhàn),我只想知道如何在C#中做一些我以前用Java做的事情)。例如,有人可以發(fā)布一個(gè)C#對(duì)應(yīng)的Sun著名的Planet枚舉示例嗎?public enum Planet {   MERCURY (3.303e+23, 2.4397e6),   VENUS   (4.869e+24, 6.0518e6),   EARTH   (5.976e+24, 6.37814e6),   MARS    (6.421e+23, 3.3972e6),   JUPITER (1.9e+27,   7.1492e7),   SATURN  (5.688e+26, 6.0268e7),   URANUS  (8.686e+25, 2.5559e7),   NEPTUNE (1.024e+26, 2.4746e7),   PLUTO   (1.27e+22,  1.137e6);   private final double mass;   // in kilograms   private final double radius; // in meters   Planet(double mass, double radius) {       this.mass = mass;       this.radius = radius;   }   public double mass()   { return mass; }   public double radius() { return radius; }   // universal gravitational constant  (m3 kg-1 s-2)   public static final double G = 6.67300E-11;   public double surfaceGravity() {       return G * mass / (radius * radius);   }   public double surfaceWeight(double otherMass) {       return otherMass * surfaceGravity();   }}// Example usage (slight modification of Sun's example):public static void main(String[] args) {     Planet pEarth = Planet.EARTH;     double earthRadius = pEarth.radius(); // Just threw it in to show usage     // Argument passed in is earth Weight.  Calculate weight on each planet:     double earthWeight = Double.parseDouble(args[0]);     double mass = earthWeight/pEarth.surfaceGravity();     for (Planet p : Planet.values())        System.out.printf("Your weight on %s is %f%n",                          p, p.surfaceWeight(mass));}// Example output:$ java Planet 175Your weight on MERCURY is 66.107583Your weight on VENUS is 158.374842[etc ...]
查看完整描述

3 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

在C#中,屬性可以與枚舉一起使用。這里有詳細(xì)描述的編程模式的好例子(Codeproject)

public enum Planet{
   [PlanetAttr(3.303e+23, 2.4397e6)]
   Mercury,
   [PlanetAttr(4.869e+24, 6.0518e6)]
   Venus}



查看完整回答
反對(duì) 回復(fù) 2019-08-15
  • 3 回答
  • 0 關(guān)注
  • 908 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)