עבור לתוכן
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.

שגיאה בלוגיקה הגורמת להדפסת אותו איבר. מה הבעיה?

Featured Replies

פורסם

בC# עשיתי מחלקה rectangle ועשיתי מערך שלה ב main זאת המחלקה :


private int height;
private int width;
private Random rnd=new Random();
public Rectangle()
{



}




public Point TopLeft
{
get { return topLeft; }
set { topLeft = value; }
}


public int Height
{
get { return height; }
set { height = value; }
}




public int Width
{
get { return width; }
set { width = value; }
}


// הצבת ערכים בצורה דינמית למלבן
public void SetRectangleRandomly()
{


this.topLeft.X = new Random().Next(0, 100);
this.topLeft.Y = new Random().Next(0, 100);
this.Height = new Random().Next(0, 100);
this.Width = new Random().Next(0, 100);
this.topLeft.X = new Random().Next(0, 100);
this.topLeft.Y = new Random().Next(0, 100);
}


}
        private Point topLeft=new Point();

בתוך המחלקה יצרתי מתודה בשם SetRectangleRandomly שכל מה שהיא צריכה לעשות זה לשים ערכים בצורה אקראית לdata members של האובייקט , כאשר יצרתי את המערך במחלקה והתחלתי כל משתנה במערך , בהדפסה ציפיתי לראות ערכים שונים אבל משום מה הוא כל הזמן מדפיס לי את אותו אובייקט , כאילו כל איבר rectangle במערך מצביע לאותו אובייקט.

אשמח לעזרה

נערך על-ידי bdoron

פורסם

א. למה אתה כל פעם עושה new Random? יצרת אובייקט rnd פעם אחת, תשתמש בו.

ב. עדיף ש-rnd יהיה static.

בכל מקרה כדאי שתקרא את ההסבר שכאן:

http://hwzone.co.il/community/threads/489659-%D7%A9%D7%90%D7%9C%D7%95%D7%AA-%D7%A0%D7%A4%D7%95%D7%A6%D7%95%D7%AA-FAQ-%D7%A9%D7%A4%D7%95%D7%AA-%D7%AA%D7%9B%D7%A0%D7%95%D7%AA?p=4414289&viewfull=1#post4414289

נערך על-ידי שניצל

ארכיון

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

דיונים חדשים

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.