marceloviana
marceloviana
Reputation Top 1%
Marcelo Viana
12 Snippets  (66th place)
Published
1 Channel
Created
4 Channels
Following
Jun 1, 2017
Last Visit
Sep 29, 2016
Registered
285 points  (88th place)
Reputation
Junior Code Generator
Serious Code Generator
Junior Publisher
Serious Publisher
Junior Trend Maker
Junior Popular Coder
Junior Autobiographer
Senior Autobiographer
Serious Famous Coder

Recent Snippets See all snippets by marceloviana

public by marceloviana created May 26, 2017  142  0  3  0

Chamando função assincrona via console

static void Main()
{
    RunAsync().Wait();
}

private static async Task RunAsync()
{
    …
}
;

public by marceloviana created Mar 29, 2017  618  0  4  0

Converte string em UFT-8

byte[] bytes = Encoding.Default.GetBytes(myString);
myString = Encoding.UTF8.GetString(bytes);
;

public by marceloviana created Dec 19, 2016  2703  0  4  0

Formatar double para ,00

//Converte double 

double valor = double.Parse("100".ToString());

string.Format("{0:n2}", decimal.Parse(valor.ToString())
;

public by marceloviana created Dec 5, 2016  1803  1  4  1

Csharp ler Json e percorrer

var url = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var sysnClient = new WebClient();
string content = sysnClient.DownloadString(url);

            
List<divida> lista_dados = new JavaScriptSerializer().Deserialize<List<cliente>>(content);

string nomecompleto = "";

foreach (divida registro in lista_dados) {
  nome_completo = registro.nome_completo;
}

txt_nomecompleto.Text = nomecompleto;
;

public by marceloviana created Nov 14, 2016  1334  14  4  0

Csharp consumindo Rest + lendo JSON

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ExemploChatBot
{
    public partial class Chat : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void enviar_Click(object sender, EventArgs e)
        {
            string txt_campo_texto = campo_texto.Text;

            var url = "http://128.0.0.1:5000/site?id=2542&texto_digitado="+ txt_campo_texto + "";

            var syncClient = new WebClient();
            var content = syncClient.DownloadString(url);            

            dynamic registro = JObject.Parse(content);
            campo_texto.Text = registro.pergunta;

        }
    }
}
;