Error: get must declare a body because it is not marked abstract or extern.

Ask general questions here.
gmaroli
Posts: 5
Joined: Wed May 22, 2019 2:25 am

Error: get must declare a body because it is not marked abstract or extern.

Post by gmaroli » Wed May 22, 2019 2:38 am

Hi ,
I am learning Ranorex (C#) on the job.
I have the below script : the main purpose of this script is to read a csv file and get the column names from that file
however when i compile the script , following error is thrown:
get must declare a body because it is not marked abstract or extern. Automatically implement properties must define both get and set accessors (CS0840)

Can anyone let me know why I get this error:
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
	
namespace Caltex.Namos.POS.ItemGroupcheck
{
	/// <summary>
	/// Description of ItemGroupcheck.
	/// </summary>
	public class ItemGroupcheck
	{
		private List<string> filecontent;
		
		public void _ItemGroupcheck(string _filename)
		{
			filecontent = File.ReadAllLines(_filename).ToList();
			var fileLines = GetLines(filecontent);
		}
		
		public List<itemLines> GetLines(List<string> lines)
		{
			var lineList = new List<itemLines>();
			foreach (var l in lines)
			{
				var l1 = new itemLines(l);
				lineList.Add(l1);
			}
			return lineList;
		}
		
	}
	public class itemLines
	{
		public string[] lineItems{ get; }  //Error is highlighted at this line
				
		public string itemgrp = lineItems[0];
		public string itemname = lineItems[1];
		
		public itemLines(string linevalue)
		{
			lineItems = linevalue.Split(',');
		}
	}
}

Thanks
G

McTurtle
Posts: 264
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Error: get must declare a body because it is not marked abstract or extern.

Post by McTurtle » Wed May 22, 2019 2:07 pm

Hi gmaroli,

According to this Compiler Error CS0840, do this:
privateset.pmg.png
privateset.pmg.png (5.64 KiB) Viewed 209 times
Does it help?

Regards,
McTurtle

gmaroli
Posts: 5
Joined: Wed May 22, 2019 2:25 am

Re: Error: get must declare a body because it is not marked abstract or extern.

Post by gmaroli » Thu May 23, 2019 12:39 am

hi Mcturtle,
That did not work.
However when I changed it as below it worked without any issues:
 public class itemLines
    {
        private string[] _lineItems;
        public string itemgrp
        {
            get { return _lineItems[0]; }
        }

        public string itemname
        {
            get { return _lineItems[1]; }
        }

        public itemLines(string linevalue)

        {
            _lineItems = linevalue.Split(',');
        }
    }
Thanks,
G

McTurtle
Posts: 264
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Error: get must declare a body because it is not marked abstract or extern.

Post by McTurtle » Thu May 23, 2019 9:33 am

Hi gmaroli,

OK, so you stopped using auto-properties :) Also fine.

Regards,
McTurtle