I am unable to convert the code into C#, Could you please help me in this regards.
Sub Joindata()
Dim mx As IMxDocument
Dim pMap As IMap
Set mx = ThisDocument
Set pMap = mx.FocusMap
' The 1st layer in the table of contents must
' be a point layer and the second must be an
' area layer.
Dim pPntLayer As IFeatureLayer
Dim pAreaLayer As IFeatureLayer
Set pPntLayer = pMap.Layer(0)
Set pAreaLayer = pMap.Layer(1)
' Get the output workspace name - make it
' the same as the input polygon layer in the join
Dim pDataset As IDataset
Dim pWkSpDataset As IDataset
Dim pWkSpName As IWorkspaceName
Set pDataset = pAreaLayer.FeatureClass
Set pWkSpDataset = pDataset.Workspace
Set pWkSpName = pWkSpDataset.FullName
' create the name object for the output join by location shapefile
Dim strOutName As String
Dim pFCName As IFeatureClassName
Dim pOutDSName As IDatasetName
Dim pName As IName
strOutName = InputBox("Enter the output shapefile name, it will create in input folder:")
Set pFCName = New FeatureClassName
With pFCName
.FeatureType = esriFTSimple
.ShapeFieldName = "Shape"
.ShapeType = esriGeometryPolygon
End With
Set pOutDSName = pFCName
With pOutDSName
.name = strOutName
Set .WorkspaceName = pWkSpName
End With
Set pName = pOutDSName
' Do a join by location that joins the attributes of the
' first point cantained within each polygon.
Dim pSpJoin As ISpatialJoin
Dim pFCNew As IFeatureClass
Dim paggopts As IAggregateOptions
Set pSpJoin = New SpatialJoin
With pSpJoin
Set .JoinTable = pPntLayer.FeatureClass
Set .SourceTable = pAreaLayer.FeatureClass
.LeftOuterJoin = True
End With
Set paggopts = pSpJoin
paggopts.IsSum = True
' setting maxMapDist to 0 means that only points within
' each each polygon will be considered
Set pFCNew = pSpJoin.JoinAggregate(pName, 0)
MsgBox "Finished"
End Sub