עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

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#

Featured Replies

פורסם

אני עכשיו באמצע שיעור ואנחנו מנסים לעשות תרגיל והמורה שלי לא יודעת את התשובה כי היא לא בדיוק יודעת C# אז אני צריך עזרה עם התרגיל הזה:

int num,pras=0;
num = int.Parse(Console.ReadLine());
switch (num)
{
case 15: pras = pras + 1000000;
case 14: pras = pras + 200000;
case 13: pras = pras + 1000;
case 12: pras = pras + 20; break;
default:

זה שCASE 15 אמור לקבל את כל הכסף של השאר

וה14 מקבל את 13 ו 12

ו13 את 12

אבל אם לא שמים BREAK בסוף הוא נותן ERROR אז איך אפשר שזה ימשיך בלי הBREAK

תודה רבה.

פורסם

ב C# עשו החלטה של עיצוב שלא לאפשר את הדבר הזה שאפשר ב C מתאמי קריאות/הבנת קוד.

פורסם

למה לא לשים BREAK?

פורסם

בדיוק בשביל הזליגה.

הוא רוצה שה-15 יקבל 1000000 + 200000 + 1000 + 20 וכו'.

פורסם
  • מחבר

נכון שניצל תודה

אין איזו דרך אחרת?

אני יהיה חייב כאילו לרשום 1201020 לראשון 201020 לשני וכו'?

פורסם

כעיקרון. בc# לא. בכל אופן לא עם case :s07:

פורסם

int num,pras=0;
num = int.Parse(Console.ReadLine());
switch (num)
{
case 15: pras = pras + 1000000; goto case 14;
case 14: pras = pras + 200000; goto case 13;
case 13: pras = pras + 1000; goto case 12;
case 12: pras = pras + 20; break;
default:

גועל נפש, אבל עובד.

פורסם
  • מחבר

תודה רבה!!

פורסם

int num,pras=0;
num = int.Parse(Console.ReadLine());
switch (num)
{
case 15: pras = pras + 1000000; goto case 14;
case 14: pras = pras + 200000; goto case 13;
case 13: pras = pras + 1000; goto case 12;
case 12: pras = pras + 20; break;
default:

גועל נפש, אבל עובד.

זה מקובל? אני לא מכיר C# כ"כ טוב, אבל לי זה נראה כמו HACK שרחוק מלהיות מקובל.

פורסם

די מוזר. עובד בכלל?

פורסם

int num,pras=0;
num = int.Parse(Console.ReadLine());
switch (num)
{
case 15: pras = pras + 1000000; goto case 14;
case 14: pras = pras + 200000; goto case 13;
case 13: pras = pras + 1000; goto case 12;
case 12: pras = pras + 20; break;
default:

גועל נפש, אבל עובד.

באמת גועל נפש. אם זכרוני איזו מטעה אותי- מיקרוסופט ממליצים בחום לא להשתמש ב goto

פורסם

1. תמחוק את הGOTO - זה עובד עם BREAK . שימוש בGOTO לא מומלץ כי הוא באופן מחייב שובר הגדרת רצף

2. יש פתרון הרבה יותר אלגנטי - אם רק תחשוב על זה עוד קצת !

פורסם

א הבנתי מה הבעיה בGOTO?

פורסם

אין בעיה, פשוט עדיף להימנע מזה אם אפשר.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

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.