The following example returns all the users from the given SharePoint Site Group using SharePoint Managed Client Side Object Model.
After creating a console application project in Visual Studio solution, add the following assembly references to the project.
Microsoft.SharePoint.Client
Microsoft.SharePoint.Client.Runtime
  1. using Microsoft.SharePoint.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. namespace GetGroupUsers
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //Get Site Url fro user
  14. Console.Write("Enter Site URL: ");
  15. string strURL = Console.ReadLine();
  16. //Get Username from user in the format of (Domain/Login ID)
  17. Console.Write("Enter UserName (domain/userid): ");
  18. string strUserName = Console.ReadLine();
  19. Console.Write("Enter your password: ");
  20. string pass = getPassword();
  21. Console.WriteLine();
  22. RETRY_GROUP:
  23. Console.Write("Enter Group Name: ");
  24. string groupName = Console.ReadLine();
  25. Console.WriteLine();
  26. try
  27. {
  28. ClientContext ctx = new ClientContext(strURL);
  29. ctx.Credentials = new NetworkCredential(strUserName, pass);
  30. Web web = ctx.Web;
  31. Group group = web.SiteGroups.GetByName(groupName);
  32. //Parameters to receive response from the server
  33. ctx.Load(web, w => w.Title);
  34. ctx.Load(group, grp => grp.Title, grp => grp.Users, grp => grp.Owner);
  35. ctx.ExecuteQuery();
  36. Console.WriteLine("Groups Name: " + group.Title);
  37. Console.WriteLine("Users Count: " + group.Users.Count);
  38. Console.WriteLine("Group Owner: " + group.Owner.Title);
  39. Console.WriteLine("Users:");
  40. foreach(User usr in group.Users)
  41. {
  42. Console.WriteLine(usr.Title);
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. Console.WriteLine("Error: " + ex.Message);
  48. Console.Write("Do you want to continue (y / n):");
  49. ConsoleKeyInfo boolContinue = Console.ReadKey();
  50. Console.WriteLine();
  51. if (boolContinue.KeyChar == 'y')
  52. goto RETRY_GROUP;
  53. else
  54. Console.Write("Enter to Exit.");
  55. }
  56. Console.Read();
  57. }
  58. private static string getPassword()
  59. {
  60. ConsoleKeyInfo key;
  61. string pass = "";
  62. do
  63. {
  64. key = Console.ReadKey(true);
  65. // Backspace Should Not Work
  66. if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
  67. {
  68. pass += key.KeyChar;
  69. Console.Write("*");
  70. }
  71. else
  72. {
  73. if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
  74. {
  75. pass = pass.Substring(0, (pass.Length - 1));
  76. Console.Write("\b \b");
  77. }
  78. }
  79. }
  80. // Stops Receving Keys Once Enter is Pressed
  81. while (key.Key != ConsoleKey.Enter);
  82. return pass;
  83. }
  84. }
  85. }
Supported Versions:

SharePoint 2013 + SharePoint Online