简体   繁体   English

C#声明一个变量作为参数,新手问题

[英]c# declaring a variable as a parameter, novice question

I've been working a week on teaching myself C# (with no C++ or Java), on a project of making an elaborate poker-hand parser. 我一直在做自己的C#(没有C ++或Java)的一个星期,从事一个制作精美的扑克手解析器的项目。 I'm finally caving in and posting my first simple question. 我终于迷上了,并发布了我的第一个简单问题。

I think I've seen variable declarations in various ways (new to my VB/A experience). 我想我已经以各种方式看到了变量声明(这对我的VB / A经验来说是新的)。 Here's the general idea of what I'd like to do. 这是我想做的一般想法。

public class CompareHandsClass : IComparer<clHiHand>

... ...

public class clCardsHeld
{   
    protected List<clCard> _liCards = new List<clCard>();

    public clCardsHeld(List<clCard> CardsList)
    {   _liCards = CardsList;
    }

... ...

public class clHiHand : clCardsHeld
{
    public clHiHand(List<clCard> CardsList) : base(CardsList) {}

    List<clCard> _liTempCards;
    CompareHandsClass HandComparer = new CompareHandsClass(); 
    ...
    if (_liTempCards.Count >= 5 
    && HandComparer.Compare(clHiHand x = new clHiHand(_liTempCards), 
                            clHiHand y = new clHiHand(_liFlushCards))) 

So my problem is down at the end with HandComparer.Compare. 所以我的问题到最后是HandComparer.Compare。 I've got two Lists of my clCard type, but I can't send them to .Compare() because that takes clHiHand objects. 我有两个clCard类型的列表,但无法将它们发送到.Compare(),因为它需要clHiHand对象。 So I'm trying to send the lists as arguments to constructors of temporary clHiHand type variables all at once. 因此,我试图一次将列表作为参数发送给临时clHiHand类型变量的构造函数。 I can do this somehow can't I (aside from using several lines of declarations)? 我可以以某种方式做到这一点(除了使用几行声明)? Thanks for any beginner's help (I'm kind of disappointed I get stumped on this little thing of all places...) 感谢您对任何初学者的帮助(我对所有地方的小事都感到失望,感到很失望...)

Oh and, PS, I hope I didn't mess up anything else in this sample code, since I've gotten away from my last working version with these extensions. 哦,PS,希望我不要弄混此示例代码中的其他内容,因为我已经脱离了带有这些扩展的上一个工作版本。

You can lose the clHiHand x and clHiHand y . 您可能会失去clHiHand xclHiHand y The call then looks like 然后通话看起来像

HandComparer.Compare(new clHiHand(_liTempCards), new clHiHand(_liFlushCards))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM