Partage
  • Partager sur Facebook
  • Partager sur Twitter

problème d'intégration code C# ASP.NET

    3 janvier 2022 à 23:14:51

    Pour intégrer du code C# dans du html, j'ai d'abord fait la partie code dans un fichier .cs.
    Par contre pour intégrer le code je ne sais pas comment faire.
    J'ai créer dans home un fichier pour le code.

    Je crois qu'il faut faire quelque chose dans la partie HomeController.cshtml dans la partie 

    J'ai déjà regarder des vidéos youtube pour ça mais ça parlait des data et sql. J'ai pas vraiment compris. 
    Merci d'avance de votre aide.

    Je met ci dessous le programme en c# 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.IO;
    
    namespace SAE11.Views.Home
    {
        public class Dictionnaire
        {
                static void Main()
                {
                    Dictionary<string, List<int>> occurencesMots = new Dictionary<string, int>();
                    occurencesMots = ConstructionIndexOccurence("page1.txt");
                    Affichage(occurencesMots);
                }
                public static Dictionary<string, List<int>> ConstructionIndexOccurence(string nomFichier)
                {
                    Dictionary<string, List<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 == ',')
                    {
                        isIgnored = true;
                    }
                    return isIgnored;
                }
                public static void AddWord(Dictionary<string, int> xOccurencesMots, string mot)
                {
                    int compteur;
                    if (!xOccurencesMots.ContainsKey(mot))
                    {
                        xOccurencesMots.Add(mot, new List<int>());
                    }
                    foreach (KeyValuePair<string, List<int>> occ in
                   xOccurencesMots)
                    {
                        foreach (int ligne in occ.Value)
                        {
                            compteur = ligne;
                            compteur = compteur + 1;
                            xOccurencesMots[mot].Add(compteur);
                        }
                    }
                    public static void Affichage(Dictionary<string, int> xOccurences)
                    {
                        foreach (KeyValuePair<string, List<int>> occ in
                       xOccurences)
                        {
                            Console.Write(occ.Key + ": ");
                            Console.Write(occ.Value + ": ");
                        }
                    }
    
            }
        }
    



    -
    Edité par m&m'ss 3 janvier 2022 à 23:17:04

    • Partager sur Facebook
    • Partager sur Twitter

    problème d'intégration code C# ASP.NET

    × 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