Partage
  • Partager sur Facebook
  • Partager sur Twitter

C# ASP.NET index.cshtml ne marche pas

    4 janvier 2022 à 8:20:27

    Je n'ai pas de messages d'erreur mais mon code ne marche.

    @{
        ViewData["Title"] = "Home page";
    }
    
    <h1>@ViewData["Title"]</h1>
    
    <div class="text-center">
        <h1 class="display-4">Welcome</h1>
    </div>
    
    @using System;
    @using System.Collections.Generic;
    @using System.IO;
    
    @functions{
    
        static void Main()
        {
            Dictionary<string, int> occurencesMots = new Dictionary<string, int>();
            occurencesMots = ConstructionIndexOccurence("page1.txt");
            Affichage(occurencesMots);
        }
        public static Dictionary<string, int> ConstructionIndexOccurence(string nomFichier)
        {
            Dictionary<string, int> occurencesMots = new Dictionary<string, int>();
            StreamReader strReader = new StreamReader(nomFichier);
            int i = 1;
            string currLine;
            while ((currLine = strReader.ReadLine()) != null)
            {
                TraitementDeLaLigne(occurencesMots, currLine);
                i++;
            }
            strReader.Close();
            return occurencesMots;
        }
        public static void TraitementDeLaLigne(Dictionary<string, int> xOccurencesMots, string ligne)
        {
            string mot = "";
    
            foreach (char ch in ligne)
            {
    
                if (!IsIgnoredChar(ch))
                {
    
                    mot += ch;
                }
    
                else if (mot != "")
                {
                    AddWord(xOccurencesMots, mot);
                    mot = "";
                }
            }
        }
        public static bool IsIgnoredChar(char ch)
        {
            bool isIgnored = false;
            if (ch == '\t' || ch == '!' || ch == ' ' || ch == '?' || ch
          == '.' || ch == ':' || ch == ';' || ch == ',' || ch == '\'')
            {
                isIgnored = true;
            }
            return isIgnored;
        }
        public static void AddWord(Dictionary<string, int> xOccurencesMots, string mot)
        {
            int compteur = 0;
            if (!xOccurencesMots.ContainsKey(mot))
            {
                compteur = compteur + 1;
                xOccurencesMots.Add(mot, compteur);
            }
            compteur = compteur + 1;
            xOccurencesMots[mot] = compteur;
        }
        public static void Affichage(Dictionary<string, int> xOccurences)
        {
            foreach (KeyValuePair<string, int> occ in xOccurences)
            {
                Console.Write(occ.Key + ": " + occ.Value + ",");
                Console.WriteLine();
            }
        }
    
    }
    

    Je voulais enfet la procédure Affichage affiche le dictionnaire. Mais quand je l'éxecute j'ai rien qui marche.

    • Partager sur Facebook
    • Partager sur Twitter

    C# ASP.NET index.cshtml ne marche pas

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown