Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

c# Bool in Int konvertieren

Empfohlene Antworten

int x = deinbool ? 1 : 0;
Würde ich nicht benutzen. Falls das irgendwann mal in .NET geändetr hätte dein Programm nen Fehler. Ist auch je nach Programmiersprache (Nicht .NET Sprachen) unterschiedlich.
int x = Convert.ToInt32(deinBoolean)

Diese möglichkeit würde ich vorziehen.

Allgemein würde ich einen bool jedoch nur wenns garnicht anders geht in einen Int umwandeln.

int x = deinbool ? 1 : 0;

Würde ich nicht benutzen. Falls das irgendwann mal in .NET geändetr hätte dein Programm nen Fehler. Ist auch je nach Programmiersprache (Nicht .NET Sprachen) unterschiedlich.

Was soll sich an den beiden möglichen Zuständen eines Bool schon ändern? IMO kann er es schon so machen, Dein Vorschlag ist natürlich trotzdem richtig.

ist es nicht so das im neue framework (2.0) die werttypen nun keine mehr sind, und bool, int etc nun auch null sein können?

ist es nicht so das im neue framework (2.0) die werttypen nun keine mehr sind, und bool, int etc nun auch null sein können?

Nein. Dafür gibt es extra die Nullable Types.

@Bubble, es kommt drauf an was du mit dem bool anfangen willst. Willst du ihn abspeichern und später wieder selbst zuweisen ist int x = myBool ? 1 : 0 wohl die beste Wahl. Willst in später nicht selbst umwandeln würde ich es nicht verwenden, da sich die Intwertigkeiten des bools theoretisch ändern könnten.

@Trux

bool? <-- .NET 2.0

bool? myBool = null;

myBool.HasValue;

bool <-- .NET 1.0,1.1 und 2.0

Willst in später nicht selbst umwandeln würde ich es nicht verwenden, da sich die Intwertigkeiten des bools theoretisch ändern könnten.

Eigentlich nicht. Eine 0 ist schon immer "unwahr" gewesen, eine 1 "wahr".

Eigentlich nicht. Eine 0 ist schon immer "unwahr" gewesen, eine 1 "wahr".

Schau dir mal Vb/Pascal/C/Phyton ... an, deine Booleanwerte werden zwischen -1 und +1 liegen. Die Definition Boolean ist je nach Sprache unterschiedlich.

Schau dir mal Vb/Pascal/C/Phyton ... an, deine Booleanwerte werden zwischen -1 und +1 liegen. Die Definition Boolean ist je nach Sprache unterschiedlich.

In C verwendet mein meist auch 0 für Falsch und 1 für Wahr.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.