Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:15:43+00:00 2026-05-17T16:15:43+00:00

I have a custom class CurvePoint which I define a set of data items

  • 0

I have a custom class CurvePoint which I define a set of data items to draw on the screen using DrawCurve

I written a cast routine to convert CurvePoint to Point, but I am getting the error
At least one element in the source array could not be cast down to the destination array type. when I try to use the .ToArray method in an Arraylist

I can cast the objects fine using the code:


Point f = new CurvePoint(.5F, .5F, new Rectangle(0, 0, 10, 10));

but if fails when using


Point[] Plots=(Point[])_Data.ToArray(typeof(Point));

(where _Data is an ArrayList which is populated with 5 CurvePoint objects)

Here is the full code:

public partial class Chart : UserControl
{
    ArrayList _Data;
    public Chart()
    {
        InitializeComponent();
        _Data = new ArrayList();
        _Data.Add(new CurvePoint(0f, 0f,this.ClientRectangle));
        _Data.Add(new CurvePoint(1f, 1f, this.ClientRectangle));
        _Data.Add(new CurvePoint(.25f, .75f, this.ClientRectangle));
        _Data.Add(new CurvePoint(.75f, .25f, this.ClientRectangle));
        _Data.Add(new CurvePoint(.5f, .6f, this.ClientRectangle));
    }
    private void Chart_Paint(object sender, PaintEventArgs e)
    {
        _Data.Sort();
        e.Graphics.FillEllipse(new SolidBrush(Color.Red),this.ClientRectangle);
        Point[] Plots=(Point[])_Data.ToArray(typeof(Point));
        e.Graphics.DrawCurve(new Pen(new SolidBrush(Color.Black)), Plots);
    }
}
public class CurvePoint : IComparable
{
    public float PlotX;
    public float PlotY;
    public Rectangle BoundingBox;
   public CurvePoint(float x, float y,Rectangle rect)
    {
        PlotX = x; PlotY = y;
        BoundingBox = rect;
    }

    public int CompareTo(object obj)
    {
        if (obj is CurvePoint)
        {
            CurvePoint cp = (CurvePoint)obj;
            return PlotX.CompareTo(cp.PlotX);
        }
        else
        { throw new ArgumentException("Object is not a CurvePoint."); }
    }
    public static implicit operator Point(CurvePoint x)
    {
        return new Point((int)(x.PlotX * x.BoundingBox.Width), (int)(x.PlotY * x.BoundingBox.Height));
    }
   public static implicit operator string(CurvePoint  x)
    {
        return x.ToString();
    }
   public override string ToString()
    {
        return "X=" + PlotX.ToString("0.0%") + " Y" + PlotY.ToString("0.0%");
    }

}

Can anyone sujest how to fix the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:15:44+00:00Added an answer on May 17, 2026 at 4:15 pm

    First, I would change your ArrayList to a strongly typed generic list, List<CurvePoint>. Then, to get your Point array, you can perform this code.

    Point[] Plots = _Data.Select(obj => (Point)obj).ToArray();
    

    If you leave it as an ArrayList, you can still do it using this code:

    Point[] Plots = (from CurvePoint obj in _Data select (Point)obj).ToArray();
    // or
    Point[] Plots = _Data.Cast<CurvePoint>().Select(obj => (Point)obj).ToArray();
    

    Edit: Finally, if you’re stuck with ArrayList and you do not have LINQ, you can do this the “long” way.

    Point[] Plots = new Point[_Data.Count];
    for (int i = 0; i < _Data.Count; i++)
    {
        Plots[i] = (Point)(CurvePoint)_Data[i];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom class Person which contains only data about person ( name, last
I have a custom class, which has some string data. I wish to be
I have a custom class that extends List which I am using as a
I have a custom class written, which I instantiate from an event procedure similar
I have a custom class which I want to load inside the firstViewController and
I have a custom class loader which extends from a URLClassLoader. I added a
I have a custom class named CatalogItem which I receive in a method, as
I have this custom class which extends EventDispatcher private var assetsManager:AssetManager; And this running
I have a custom class MyFutureTask extends FutureTask<Void> upon which I do some code
I am working with the SQLMemebershipProvider and using Profiles. I have a custom class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.