IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Besoin d'explication d'un bout de code


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juillet 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juillet 2015
    Messages : 18
    Par défaut Besoin d'explication d'un bout de code
    Bonjour tous,

    Je veux reproduire un programme mais je ne comprends pas certaines parties. Je vous sollicite pour m'expliquer terre à terre ce code.

    Merci


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data.Linq.Mapping;
    using System.IO;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Text;
     
    namespace Bet2Day.RF2.Core
    {
      [Table(Name = "dbo.Race")]
      [DataContract]
      [Serializable]
      public class Race : ICloneable, INotifyPropertyChanging, INotifyPropertyChanged
      {
        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(string.Empty);
        private Dictionary<int, Odd> _specialOdds = new Dictionary<int, Odd>();
        private Decimal _stake = new Decimal();
        private Decimal _win = new Decimal();
        private int _countdown = 0;
        private string _result = string.Empty;
        private RaceDisplayState _state = RaceDisplayState.RUNNING;
        private Odd[] _winnerOdds;
        private Odd[] _podiumOdds;
        private Odd[,] _doubleOdds;
        private int _RaceID;
        private int _OddPoolID;
        private int _RaceTypeID;
        private int _RaceCycleID;
        private int? _MovieID;
        private int _RaceNumber;
        private DateTime _StartRaceDate;
        private DateTime? _StartMovieDate;
        private bool _Calculated;
        private bool _DoubleWin;
     
        public Movie Movie { get; set; }
     
        public Race(int raceNumber, DateTime startDate, int starters)
        {
          this.RaceNumber = raceNumber;
          this.StartRaceDate = startDate;
        }
     
        public Decimal Stake
        {
          get
          {
            return this._stake;
          }
          set
          {
            this._stake = value;
            this.SendPropertyChanged(nameof (Stake));
          }
        }
     
        public Decimal Win
        {
          get
          {
            return this._win;
          }
          set
          {
            this._win = value;
            this.SendPropertyChanged(nameof (Win));
          }
        }
     
        public int Countdown
        {
          get
          {
            return this._countdown;
          }
          set
          {
            this._countdown = value;
            this.SendPropertyChanged(nameof (Countdown));
          }
        }
     
        public string Result
        {
          get
          {
            return this._result;
          }
          set
          {
            this._result = value;
            this.SendPropertyChanged(nameof (Result));
          }
        }
     
        public RaceDisplayState State
        {
          get
          {
            return this._state;
          }
          set
          {
            this._state = value;
            this.SendPropertyChanged(nameof (State));
          }
        }
     
        public Odd[] WinnerOdds
        {
          set
          {
            this._winnerOdds = value;
          }
          get
          {
            return this._winnerOdds;
          }
        }
     
        public Odd[] PodiumOdds
        {
          set
          {
            this._podiumOdds = value;
          }
          get
          {
            return this._podiumOdds;
          }
        }
     
        public Odd[,] DoubleOdds
        {
          set
          {
            this._doubleOdds = value;
          }
          get
          {
            return this._doubleOdds;
          }
        }
     
        public Dictionary<int, Odd> SpecialOdds
        {
          set
          {
            this._specialOdds = value;
          }
          get
          {
            return this._specialOdds;
          }
        }
     
        public void SetOddGraduation(int winnerPayoff, int podiumPayoff, int doublePayoff)
        {
          double num1 = this.CalcCurrentGraduation(BetType.WINNER);
          double num2 = this.CalcCurrentGraduation(BetType.PODIUM);
          double num3 = this.CalcCurrentGraduation(BetType.DOUBLE);
          if (this._winnerOdds != null && this._podiumOdds != null)
          {
            for (int index = 0; index < this._winnerOdds.Length; ++index)
            {
              double num4 = Math.Round(this._winnerOdds[index].Value / num1 * ((double) winnerPayoff / 100.0), 1);
              double num5 = Math.Round(this._podiumOdds[index].Value / num2 * ((double) podiumPayoff / 100.0), 1);
              this._winnerOdds[index].Value = num4 <= 1.0 ? 1.1 : num4;
              this._podiumOdds[index].Value = num5 <= 1.0 ? 1.1 : num5;
            }
          }
          if (this._doubleOdds != null)
          {
            Odd[,] doubleOdds = this._doubleOdds;
            int upperBound1 = doubleOdds.GetUpperBound(0);
            int upperBound2 = doubleOdds.GetUpperBound(1);
            for (int lowerBound1 = doubleOdds.GetLowerBound(0); lowerBound1 <= upperBound1; ++lowerBound1)
            {
              for (int lowerBound2 = doubleOdds.GetLowerBound(1); lowerBound2 <= upperBound2; ++lowerBound2)
              {
                Odd odd = doubleOdds[lowerBound1, lowerBound2];
                if (odd != null)
                {
                  double num4 = odd.Value / num3 * ((double) doublePayoff / 100.0);
                  odd.Value = Math.Round(num4, num4 >= 100.0 ? 0 : 1);
                }
              }
            }
          }
          double num6 = 0.0;
          double num7 = 0.0;
          double num8 = 0.0;
          double num9 = 0.0;
          int length = this.WinnerOdds.Length;
          for (int index = 0; index < length; ++index)
          {
            if (index < length / 2)
              num6 += 1.0 / this.WinnerOdds[index].Value;
            else
              num7 += 1.0 / this.WinnerOdds[index].Value;
            if ((index + 1) % 2 == 0)
              num9 += 1.0 / this.WinnerOdds[index].Value;
            else
              num8 += 1.0 / this.WinnerOdds[index].Value;
          }
          double num10 = num6;
          double num11 = num7;
          double num12 = num8;
          double num13 = num9;
          double num14 = Math.Round(1.0 / num10 / (1.0 / (num10 + num11)) * ((double) podiumPayoff / 100.0), 1);
          double num15 = Math.Round(1.0 / num11 / (1.0 / (num10 + num11)) * ((double) podiumPayoff / 100.0), 1);
          double num16 = Math.Round(1.0 / num13 / (1.0 / (num13 + num12)) * ((double) podiumPayoff / 100.0), 1);
          double num17 = Math.Round(1.0 / num12 / (1.0 / (num13 + num12)) * ((double) podiumPayoff / 100.0), 1);
          double oddValue1 = num14 > 1.0 ? num14 : 1.1;
          double oddValue2 = num15 > 1.0 ? num15 : 1.1;
          double oddValue3 = num16 > 1.0 ? num16 : 1.1;
          double oddValue4 = num17 > 1.0 ? num17 : 1.1;
          this.SpecialOdds.Clear();
          this.SpecialOdds.Add(-1, new Odd(-1, (short) 0, (short) 0, (short) 0, oddValue1));
          this.SpecialOdds.Add(-2, new Odd(-2, (short) 0, (short) 0, (short) 0, oddValue2));
          this.SpecialOdds.Add(-4, new Odd(-4, (short) 0, (short) 0, (short) 0, oddValue3));
          this.SpecialOdds.Add(-3, new Odd(-3, (short) 0, (short) 0, (short) 0, oddValue4));
        }
     
        public double CalcCurrentGraduation(BetType betType)
        {
          double num = 0.0;
          switch (betType)
          {
            case BetType.WINNER:
              num = 1.0 / ((IEnumerable<Odd>) this._winnerOdds).Sum<Odd>((Func<Odd, double>) (id => 1.0 / id.Value));
              break;
            case BetType.PODIUM:
              num = (double) this.GetPodiumWinner() / ((IEnumerable<Odd>) this._podiumOdds).Sum<Odd>((Func<Odd, double>) (id => 1.0 / id.Value));
              break;
            case BetType.DOUBLE:
              Odd[,] doubleOdds = this._doubleOdds;
              int upperBound1 = doubleOdds.GetUpperBound(0);
              int upperBound2 = doubleOdds.GetUpperBound(1);
              for (int lowerBound1 = doubleOdds.GetLowerBound(0); lowerBound1 <= upperBound1; ++lowerBound1)
              {
                for (int lowerBound2 = doubleOdds.GetLowerBound(1); lowerBound2 <= upperBound2; ++lowerBound2)
                {
                  Odd odd = doubleOdds[lowerBound1, lowerBound2];
                  if (odd != null)
                    num += 1.0 / odd.Value;
                }
              }
              num = 1.0 / num;
              break;
          }
          return Math.Round(num, 2);
        }
     
        private int GetPodiumWinner()
        {
          if (this._podiumOdds != null)
          {
            if (this._podiumOdds.Length == 6)
              return 2;
            if (this._podiumOdds.Length == 8)
              return 3;
          }
          return 0;
        }
     
        public override string ToString()
        {
          return this.ToString(false);
        }
     
        public virtual string ToString(bool idOnly)
        {
          StringBuilder stringBuilder = new StringBuilder();
          stringBuilder.Append("Race[ ");
          stringBuilder.AppendFormat("RaceID={0} ", (object) this.RaceID);
          stringBuilder.AppendFormat("RaceNumber={0} ", (object) this.RaceNumber);
          if (idOnly)
            return stringBuilder.ToString();
          stringBuilder.AppendFormat("RaceTypeID={0} ", (object) string.Concat((object) this.RaceTypeID));
          stringBuilder.AppendFormat("MovieID={0} ", (object) string.Concat((object) this.MovieID));
          stringBuilder.AppendFormat("Calculated={0} ", (object) (this.Calculated.ToString() ?? ""));
          stringBuilder.AppendFormat("OddPoolID={0} ", (object) string.Concat((object) this.OddPoolID));
          DateTime startRaceDate = this.StartRaceDate;
          if (true)
            stringBuilder.Append("StartRaceDate= " + this.StartRaceDate.ToString() + " ");
          else
            stringBuilder.Append("StartRaceDate=null ");
          if (this.StartMovieDate.HasValue)
            stringBuilder.Append("StartMovieDate= " + this.StartMovieDate.Value.ToString() + " ");
          else
            stringBuilder.Append("StartMovieDate=null ");
          if (this.WinnerOdds != null)
            stringBuilder.AppendFormat("WinnerOdds={0} ", (object) string.Concat((object) this.WinnerOdds.Length));
          if (this.PodiumOdds != null)
            stringBuilder.AppendFormat("PodiumOdds={0} ", (object) string.Concat((object) this.PodiumOdds.Length));
          if (this.DoubleOdds != null)
            stringBuilder.AppendFormat("DoubleOdds={0} ", (object) string.Concat((object) this.DoubleOdds.Length));
          if (this.SpecialOdds != null)
            stringBuilder.AppendFormat("SpecialOdds={0} ", (object) string.Concat((object) this.SpecialOdds.Count));
          stringBuilder.Append("]");
          return stringBuilder.ToString();
        }
     
        public Race DeepCopy()
        {
          MemoryStream memoryStream = new MemoryStream();
          BinaryFormatter binaryFormatter = new BinaryFormatter();
          binaryFormatter.Serialize((Stream) memoryStream, (object) this);
          memoryStream.Position = 0L;
          Race race = (Race) binaryFormatter.Deserialize((Stream) memoryStream);
          race.PropertyChanged = (PropertyChangedEventHandler) null;
          race.PropertyChanging = (PropertyChangingEventHandler) null;
          memoryStream.Close();
          return race;
        }
     
        public void Detach()
        {
          this.PropertyChanged = (PropertyChangedEventHandler) null;
          this.PropertyChanging = (PropertyChangingEventHandler) null;
        }
     
        public object Clone()
        {
          Race race = (Race) this.MemberwiseClone();
          race.PropertyChanged = (PropertyChangedEventHandler) null;
          race.PropertyChanging = (PropertyChangingEventHandler) null;
          return (object) race;
        }
     
        public Race()
        {
          this.Initialize();
        }
     
        [Column(AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true, Storage = "_RaceID")]
        [DataMember(Order = 1)]
        public int RaceID
        {
          get
          {
            return this._RaceID;
          }
          set
          {
            if (this._RaceID == value)
              return;
            this.SendPropertyChanging();
            this._RaceID = value;
            this.SendPropertyChanged(nameof (RaceID));
          }
        }
     
        [Column(DbType = "Int NOT NULL", Storage = "_OddPoolID")]
        [DataMember(Order = 2)]
        public int OddPoolID
        {
          get
          {
            return this._OddPoolID;
          }
          set
          {
            if (this._OddPoolID == value)
              return;
            this.SendPropertyChanging();
            this._OddPoolID = value;
            this.SendPropertyChanged(nameof (OddPoolID));
          }
        }
     
        [Column(DbType = "Int NOT NULL", Storage = "_RaceTypeID")]
        [DataMember(Order = 3)]
        public int RaceTypeID
        {
          get
          {
            return this._RaceTypeID;
          }
          set
          {
            if (this._RaceTypeID == value)
              return;
            this.SendPropertyChanging();
            this._RaceTypeID = value;
            this.SendPropertyChanged(nameof (RaceTypeID));
          }
        }
     
        [Column(DbType = "Int NOT NULL", Storage = "_RaceCycleID")]
        [DataMember(Order = 4)]
        public int RaceCycleID
        {
          get
          {
            return this._RaceCycleID;
          }
          set
          {
            if (this._RaceCycleID == value)
              return;
            this.SendPropertyChanging();
            this._RaceCycleID = value;
            this.SendPropertyChanged(nameof (RaceCycleID));
          }
        }
     
        [Column(DbType = "Int", Storage = "_MovieID")]
        [DataMember(Order = 5)]
        public int? MovieID
        {
          get
          {
            return this._MovieID;
          }
          set
          {
            int? movieId = this._MovieID;
            int? nullable = value;
            if (movieId.GetValueOrDefault() == nullable.GetValueOrDefault() && movieId.HasValue == nullable.HasValue)
              return;
            this.SendPropertyChanging();
            this._MovieID = value;
            this.SendPropertyChanged(nameof (MovieID));
          }
        }
     
        [Column(DbType = "Int NOT NULL", Storage = "_RaceNumber")]
        [DataMember(Order = 6)]
        public int RaceNumber
        {
          get
          {
            return this._RaceNumber;
          }
          set
          {
            if (this._RaceNumber == value)
              return;
            this.SendPropertyChanging();
            this._RaceNumber = value;
            this.SendPropertyChanged(nameof (RaceNumber));
          }
        }
     
        [Column(DbType = "DateTime NOT NULL", Storage = "_StartRaceDate")]
        [DataMember(Order = 7)]
        public DateTime StartRaceDate
        {
          get
          {
            return this._StartRaceDate;
          }
          set
          {
            if (!(this._StartRaceDate != value))
              return;
            this.SendPropertyChanging();
            this._StartRaceDate = value;
            this.SendPropertyChanged(nameof (StartRaceDate));
          }
        }
     
        [Column(DbType = "DateTime", Storage = "_StartMovieDate")]
        [DataMember(Order = 8)]
        public DateTime? StartMovieDate
        {
          get
          {
            return this._StartMovieDate;
          }
          set
          {
            DateTime? startMovieDate = this._StartMovieDate;
            DateTime? nullable = value;
            if (startMovieDate.HasValue == nullable.HasValue && (!startMovieDate.HasValue || !(startMovieDate.GetValueOrDefault() != nullable.GetValueOrDefault())))
              return;
            this.SendPropertyChanging();
            this._StartMovieDate = value;
            this.SendPropertyChanged(nameof (StartMovieDate));
          }
        }
     
        [Column(DbType = "Bit NOT NULL", Storage = "_Calculated")]
        [DataMember(Order = 9)]
        public bool Calculated
        {
          get
          {
            return this._Calculated;
          }
          set
          {
            if (this._Calculated == value)
              return;
            this.SendPropertyChanging();
            this._Calculated = value;
            this.SendPropertyChanged(nameof (Calculated));
          }
        }
     
        [Column(DbType = "Bit NOT NULL", Storage = "_DoubleWin")]
        [DataMember(Order = 10)]
        public bool DoubleWin
        {
          get
          {
            return this._DoubleWin;
          }
          set
          {
            if (this._DoubleWin == value)
              return;
            this.SendPropertyChanging();
            this._DoubleWin = value;
            this.SendPropertyChanged(nameof (DoubleWin));
          }
        }
     
        public event PropertyChangingEventHandler PropertyChanging;
     
        public event PropertyChangedEventHandler PropertyChanged;
     
        protected virtual void SendPropertyChanging()
        {
          if (this.PropertyChanging == null)
            return;
          this.PropertyChanging((object) this, Race.emptyChangingEventArgs);
        }
     
        protected virtual void SendPropertyChanged(string propertyName)
        {
          if (this.PropertyChanged == null)
            return;
          this.PropertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
        }
     
        private void Initialize()
        {
        }
     
        [OnDeserializing]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public void OnDeserializing(StreamingContext context)
        {
          this.Initialize();
        }
      }
    }

  2. #2
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 218
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 218
    Par défaut
    Il y a de quoi en faire un roman.

    Une question en particulier sur les "certaines parties" ?

  3. #3
    Membre chevronné Avatar de pascalCH
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Juillet 2006
    Messages
    188
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juillet 2006
    Messages : 188
    Par défaut
    vu le "bout" de code, il serait sympa d'avoir une idée sur quelles parties nécessitent des explications ...en ajoutant de ci de là, quelques commentaires

Discussions similaires

  1. Explication d'un bout de code
    Par askamel dans le forum ActionScript 3
    Réponses: 1
    Dernier message: 22/02/2012, 18h57
  2. Besoin d'explication d'une ligne de codes
    Par cdevl32 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 16/10/2007, 23h53
  3. explication d'un bout de code ASP
    Par mademoizel dans le forum ASP
    Réponses: 4
    Dernier message: 22/05/2007, 14h03
  4. explication sur un bout de code
    Par poporiding dans le forum C++
    Réponses: 2
    Dernier message: 27/06/2006, 19h04
  5. Besoin d'explications sur un bout de code
    Par zizitop dans le forum C
    Réponses: 7
    Dernier message: 26/04/2005, 15h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo