3 Replies - 1988 Views - Last Post: 14 December 2010 - 11:30 PM Rate Topic: -----

#1 ni44ko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 23-November 10

string.count method not working in c# 2005

Posted 14 December 2010 - 09:30 PM

I have finished a project of mine in c# 2008. but now i need to redo it again to c# 2005 to create an installer(setup and deployment) but i realized that there's no .count method in c# 2005. Please show me the proper conversion of the code below(error is : int cardCount = draw.Count(card => card.StartsWith(value));) it's a video poker program btw

string[] values = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
            string[] suits = { "♠", "♦", "♣", "♥" };

            string[] draw = { "A ♠", "A ♦", "K ♦", "K ♥", "A ♥" };

            Boolean threeOf = false;
            Boolean twoOf = false;
            Boolean fullHouse = false;

            // full house, 3 cards of one value, 2 cards of another value
            foreach (string value in values)
            {
                int cardCount = draw.Count(card => card.StartsWith(value));//NOT WORKING
                if (cardCount == 3)
                { threeOf = true; }
               
                if (cardCount == 2)
                { twoOf = true; }
            }

            if (threeOf && twoOf)
            { fullHouse = true; }



This post has been edited by ni44ko: 14 December 2010 - 09:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: string.count method not working in c# 2005

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: string.count method not working in c# 2005

Posted 14 December 2010 - 11:21 PM

Linq came in .NET 3.5 and I assume C# 2005 means .NET 2.0 so there is no linq.

You can create a new method where you give your 'draw' array and 'value' string as parameter and return an int.
Was This Post Helpful? 1
  • +
  • -

#3 Zunera  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 74
  • Joined: 07-December 10

Re: string.count method not working in c# 2005

Posted 14 December 2010 - 11:26 PM

Hi,
I really don't understand why you need to redo it in VS2005 - you can create installer/... also in VS2008?!
However, you need to replace the LinQ expression by a loop like:
int Count(string[] draw, String value)
{
  int result = 0;
  for(int i=0; i<draw.Length;i++) if(draw[i].StartsWith(value)) result++;
  return result;
}


By your question it seems you have no glue what even happens within the 'draw.Count(card => ...)' method so you might take a look here.
Was This Post Helpful? 0
  • +
  • -

#4 ni44ko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 23-November 10

Re: string.count method not working in c# 2005

Posted 14 December 2010 - 11:30 PM

got it thaks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1