Posts by vik • 2,208 points
88 posts
-
0
votes1
answer33
viewsA: How to use Linq in 2 lists so that one complements the other in C#
Your two examples (in c#) do not present the same results! The first (with chained foreach) the list gets the 4 elements and the second (with Join and select) the list gets only the 2 elements where…
-
3
votes3
answers101
viewsA: Operator ?: does not work
Another solution: Documento = (c.FaturaContasReceberP?.NotaFiscal?.ToString().Insert(0, "Fat. NFSe: ") + c.FaturaContasReceberP?.NotaFiscalProdutos?.ToString().Insert(0, " NFe: ")).Trim(); Should…
-
1
votes2
answers252
viewsA: Power with For or While
c# static void Main(string[] args) { Console.WriteLine("Base: "); int myBase = int.Parse(Console.ReadLine()); Console.WriteLine("Potencia: "); int myPow = int.Parse(Console.ReadLine()); int result =…
-
1
votes1
answer109
viewsA: How to resize 2 Datagridview equally?
One option would be to use the control Tablelayoutpanel with the property Dock to Fill, has even the option to put the column width in percentage. Each cell only allows a control, use a container if…
-
2
votes1
answer78
viewsA: Hide Datagridview lines by date comparison
// Para evitar erro caso a linha selectionada seja para esconder. dgvDados.CurrentCell = null; foreach (DataGridViewRow row in dgvDados.Rows) { if (row.Cells["data"].Value is DateTime) { DateTime d…
-
1
votes2
answers518
viewsA: How to group a list of objects and after the grouping, get the list of objects that have the lowest value in c#?
Another option would be to implement the interface IEqualityComparer<T> and use the extension Distinct(): public class Produto : IEqualityComparer<Produto> { public string Nome { get;…
-
1
votes2
answers609
viewsA: Banknotes and coins C#
Let’s assume that the price of a product is R$ 4.99 and you want to know the total value of 17 items of that product. Below we have the code used to make the calculation using the type float for the…
-
4
votes1
answer107
viewsA: Foreach in Datatable
Assuming CatRem_Tipo is the name of the column: var dic = new Dictionary<string, string> { { "C", "Comissão/Participação" }, { "P", "Premiação" }, { "A", "Ambos" } }; foreach (DataRow dataRow…
-
4
votes5
answers5490
views -
4
votes3
answers59
viewsA: Convert inside a lambda
campo1 = campo2 ?? default; The operator ?? is called null coalescence operator. It will return the left operand if the operand is not null; otherwise it will return the right operand.…
-
3
votes3
answers297
viewsA: Concatenate and convert string array into int
Another option would be the method Concat int result = int.Parse(string.Concat(matriz)); It is worth remembering that new string[2] makes the array have only 2 elements (0 and 1)…
-
1
votes4
answers152
viewsA: How to know the exact line of a Nullreferenceexception error when creating a new instance of an object with multiple properties
You can use an auxiliary method to allow you to debug. T BreakMe<T>(Func<T> func) { Debugger.Break(); return func(); } I’d wear it like this: var ocorrencias =…
-
1
votes3
answers101
viewsA: C# Object reference not defined for an object instance
It is not a direct answer to the question, but with Ingles you can simplify your code: static void Main(string[] args) { String[] text = System.IO.File.ReadAllLines(@"C:\Users\Pedro…
-
1
votes1
answer58
viewsA: How to Show a split result on the screen
When you make a division between two integers (int), the result will be integer.. ex: 8 / 10 = 0 if you want 0.8 you will have to convert one of the values to double, or another type that accepts…
-
1
votes1
answer52
viewsA: Parameter is not Valid - Picturebox in C#
The mistake is why you’re calling the method Show() after making Dispose() in the Image property of the picturebox (through the close button). I can’t explain what’s causing the mistake internally,…
-
1
votes2
answers203
viewsA: How to Split a List Proportionately 32%, 32% and 36%
See if this is it: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ConsoleApp14 { class Program { static void Main(string[]…
-
2
votes2
answers190
viewsA: Keyboard events in C# in textbox
Change the property Keypreview from form to true And in the Form Keypress event: private void Form1_KeyPress(object sender, KeyPressEventArgs e) { // Precisa fazer para aceitar apenas caracteres…
-
2
votes2
answers425
viewsA: Asynchronous alternative to Thread.Sleep without locking application in C#
You can get the same result without using the timer: public void Await(int milliseconds) { DateTime dateTimeTarget = DateTime.Now.AddMilliseconds(milliseconds); while (DateTime.Now <…
-
9
votes3
answers20560
viewsA: Pick first and last name and abbreviate middle names only with the initial
One more example using and abusing Linq... string nome = "Rafael Rodrigues Arruda de Oliveira"; var preposicoes = new string[] { "de", "da", "do", "das", "dos" }; var nomes = nome.ToLower().Split('…
-
1
votes1
answer328
viewsA: How to return the last Record of an SQL column in a textbox?
When you only need one value you can and should use the Executescalar The code would look something like this: string sql = "SELECT MAX(cod_cli) FROM cad_cli"; using (var conn = new…
-
2
votes1
answer147
viewsA: Out of Memory when placing image in Picturebox c#
You’re creating an instance of FileStream and you don’t get to use it. Or load the image through the method Image.FromStream() and then you need the var fileStream that you have in the code, or…
-
1
votes7
answers1103
viewsA: Remove part of string until nth occurrence of a character
One more solution: var texto = "0001>0002>0003>0004>0005"; for (int i = texto.Length - 1, sinal = 0; i >= 0 && sinal < 2; i--) { sinal += texto[i] == '>' ? 1 : 0; texto…
-
-1
votes2
answers105
viewsA: How to change the value of several variables of the same type, for the same value, at once?
valueBool.All(x => x = resetTo); Nor would it change the value of array elements within the method itself, if it were to change the value of a property: valueBool.All(x => {x.propriedade =…
-
3
votes2
answers395
viewsA: How to assign a default date on a Datetime type object in C#?
public DateTime OrderDateDeli { get { return orderDateDeli; } set { orderDateMade = DateTime.Today; } // está orderDateMade em vez de orderDateDeli } From C # 3.0, the properties resource has been…
-
1
votes3
answers92
viewsA: Leave date only on the datatime, without the hours part
Cba_dt_abertura = DateTime.Parse(x.Cba_dt_abertura.ToString()).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
-
0
votes2
answers88
viewsA: I want to leave a string with Zero value
Since you are to receive the string n1 of a textbox, could and should use a Tryparse if (double.TryParse(TxtNumeroExtenso.Text.Replace('.',','), NumberStyles.Currency, new CultureInfo("pt-BR"), out…
-
1
votes1
answer98
viewsA: Web Scraping or Web Crawler isolate Node
I couldn’t get on that site either, everything on <section class="currencies"></section> does not appear.. try another site: var url = @"https://themoneyconverter.com/USD/BRL.aspx"; var…
-
0
votes2
answers158
viewsA: Incorrect formatting of string to decimal during Excel import
cliente.Faturamento = Convert.ToDecimal(workSheet.Cells[i, j].Value.ToString()); When using Tryparse, you already have the value in the variable faturamento... If the resultado for true:…
-
1
votes2
answers85
viewsA: Randomly generated numbers with arrays are repeated
An idea would be to use a List<int> or Queue<int> to store the numbers instead of an array, because later Voce needs to remove the "chosen element".. With a Queue<int> that it…
-
3
votes2
answers67
viewsA: How to know if all Abels with numbers are filled
If your dashboard contains only Labels, can do the following to count how many Abels have the BackColor in orange: int totalDeLaranjas = panel1.Controls.Cast<Label>().Count(lbl =>…
-
3
votes3
answers470
viewsA: Left Join with LINQ
Lambda would be something like that: var result = ListA.Where(x => !ListB.Any(y => y.Codigo == x.Codigo));
-
1
votes1
answer60
views -
1
votes2
answers114
viewsA: Using the Click event inside an IF
After creating the events, do the comparison there. private void lblCor_Click(object sender, EventArgs e) { var lbl = (Label)sender; if (lbl.Text == lblNum.Text) { lbl.BackColor = Color.Orange; } }…
-
3
votes3
answers127
views -
2
votes3
answers196
viewsA: Growth ranges of an array’s values
Seems to be ok: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ConsoleApp2 { class Interval { public int Min { get; set; }…
-
4
votes2
answers63
viewsA: Problem Trying to query Application c# + Database
Cpf_Cpnj should be Cpf_Cnpj in the following line: Cpf_Cnpj = dt.Rows[i]["Cpf_Cpnj"].ToString(), // Problema ocorre nesta linha…
-
0
votes1
answer44
viewsA: c# Change control properties of another file
In order to have access to an object of another class this object cannot be private Put a getter to access this object. in Login.Cs public Panel Panel1 { get { return this.panel1; } } public Panel…
-
1
votes2
answers207
viewsA: Method and Sub-programme
In object oriented programming these subprograms are called methods and may or may not return values. In structured programming these subprograms call themselves functions when they return something…