For version 9.0 please check the below post
RetrieveTotalRecordCountRequest
https://dreamingincrm.com/2019/07/22/getting-entity-record-counts/
https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.retrievetotalrecordcountrequest?view=dynamics-general-ce-9
Just sharing a sample code to get the total number of records (e.g. account here)
<br />
IOrganizationService orgService = GetOrganizationService();</p>
<p> int totalCount = 0;</p>
<p> QueryExpression query = new QueryExpression("account");<br />
query.ColumnSet = new ColumnSet();<br />
query.Distinct = true;<br />
query.ColumnSet.AddColumn("accountid");<br />
query.PageInfo = new PagingInfo();<br />
query.PageInfo.Count = 5000;<br />
query.PageInfo.PageNumber = 1;<br />
query.PageInfo.ReturnTotalRecordCount = true;</p>
<p> EntityCollection entityCollection = orgService.RetrieveMultiple(query);<br />
totalCount = entityCollection.Entities.Count;</p>
<p> while (entityCollection.MoreRecords)<br />
{<br />
query.PageInfo.PageNumber += 1;<br />
query.PageInfo.PagingCookie = entityCollection.PagingCookie;<br />
entityCollection = orgService.RetrieveMultiple(query);<br />
totalCount = totalCount + entityCollection.Entities.Count;<br />
} </p>
<p> MessageBox.Show(totalCount.ToString());<br />
Hope it helps