में किसी सूची में सामान जोड़ना मैं f # में "2 डी आकार संपादक" नामक एक प्रोजेक्ट कर रहा हूं। मैंने इस परियोजना को सी # में पहले किया है, इसलिए मुझे दो आकारों को जोड़ने के लिए सभी तर्क मिल गए हैं। तो मुझे पता है कि मुझे उन सभी आकारों को पकड़ने के लिए एक सूची की आवश्यकता होगी जो मैं जोड़ रहा हूं। लेकिन मैं बस काम करने के लिए अपनी addToList विधि नहीं मिल सकता है।f #
मेरे ShapeList:
let mutable ShapeList:List<RectangleZ> = [RectangleZ(100,100)]
मेरे ऐड तरीके:
let addToList (listan:List<RectangleZ>) (element:RectangleZ) = let ShapeList = [email protected][element] in ShapeList
//Method to add into the ShapeList
let addToList (listan:List<RectangleZ>) (element:RectangleZ) = element::ShapeList
//Other try on adding into shapeList
बटन कि ShapeList को आयतों को जोड़ने की जानी चाहिए:
btn.Click.Add(fun _ -> new RectangleZ(500, 100) |> addToList ShapeList |>ignore |> saver)
//Button click method that should be adding the RectangleZ(500, 100) to my ShapeList
और बिल्कुल मेरी आयत:
type RectangleZ(x:int, y:int)=
let mutable thisx = x
let mutable thisy = y
let mutable thiswidth = 50
let mutable thisheight = 20
let brush = new SolidBrush(Color.Black)
member obj.x with get() = thisx and set x = thisx <- x
member obj.y with get() = thisy and set y = thisy <- y
member obj.width with get() = thiswidth and set width = thiswidth <- width
member obj.height with get() = thisheight and set height = thisheight <- height
member obj.thisColor = Color.FromArgb(167, 198, 253)
member obj.draw(paper:Graphics) = paper.FillRectangle(brush, thisx, thisy, 50, 20)
member obj.ShapeType = "Rectangle"
तत्व मेरे addToList कार्यों में से किसी भी कारण से सूची में शामिल नहीं किया गया है। मेरा सवाल है क्यों?
हाँ, सही ढंग से काम किया! मेरा आकार सूची अब अपने मूल्यों को अद्यतन करता है! धन्यवाद! –