This should give you the idea.
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace GetVertices
{
public class getvertices
{
[CommandMethod("GetVerts")]
public void getVerts()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityResult res = ed.GetEntity("\nSelect Polyline: ");
if (res.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Curve oCrv = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as Curve;
Point3d pt1 = oCrv.GetClosestPointTo(res.PickedPoint, false);
double param_pt1 = oCrv.GetParameterAtPoint(pt1);
double param1 = (double)Math.Floor(param_pt1);
double param2 = param1 + 1;
Point3d v1 = oCrv.GetPointAtParameter(param1);
Point3d v2 = oCrv.GetPointAtParameter(param2);
ed.WriteMessage("\nVert1=" + v1.ToString() + ", Vert2=" + v2.ToString());
}
}
}
}