Posts by MurariAlex • 2,150 points
51 posts
-
1
votes2
answers202
viewsA: Why do we pass an object to the statement lock?
This object is going "keep" the lock information. When the first thread enters the method and calls the lock, the object obj (or padlock, in your example) is going to be with the status locked and…
-
4
votes3
answers230
viewsA: Why are methods that operate pointers insecure in . NET?
C# is a language with type security (type-Safety) But what would be type security? The easiest way to explain this is to explain how contrary of this. In languages such as C or C++ you can do things…
-
1
votes1
answer213
viewsA: How to repeat number at a maximum?
If I understand correctly, it’s this logic you want: Obs.: Doing as you specified ("from zero index"), the values are not equal to those you showed. Note that in your question, in your last example,…
-
3
votes3
answers1724
viewsA: Add Datagrid column with valid values only
Modify your foreach to consider only lines containing the column valor nonempty. I’m using LINQ and C# 6. using System.Linq; foreach (DataGridViewRow row in…
-
2
votes1
answer721
viewsA: How to join two tables using auxiliary table and LINQ
I did the query in LINQ who gets people and representatives through the table that binds representatives to people, I made some style changes in her class so that it stays in a more concise pattern.…
-
4
votes1
answer378
viewsA: Force user to select Radio Button inside the Groupbox
Using LINQ can stay like this: using System.Linq; // gbRadioButtons - Nome do seu groupBox que contém os radio buttons. var anySelected = gbRadioButtons.Controls.OfType<RadioButton>().Any(x…
-
2
votes1
answer298
viewsA: How to make a SUM in different table fields in the Entity Framework?
Below is the version on LINQ and the tables I used in this example. Query LINQ var result = from oi in ctx.OrcamentoItem // onde ctx é o contexto do EF join iv in ctx.InsumoValor on oi.Codigo equals…
-
1
votes1
answer497
viewsA: Data type Mismatch in criteria Expression + Excel data handling
The problem is that things are being done in the wrong order. You are running the command before specifying the parameters with the values. dts = cmd.ExecuteReader(); // Executa o comando (query)…
-
5
votes2
answers624
viewsA: When using optional parameters above overloading and vice versa?
Technical limitations Exposing methods with optional parameters such as Apis to other languages that do not support this feature generates problems, in this case method overload is recommended.…
-
2
votes1
answer356
viewsA: MVVM, Should I use Icommand on all controls?
Yes, my opinion is that you should use Commands in all situations, as it maintains the consistency of the standard MVVM and does not cause confusion, because mixing code-behind with MVVM will cause…
-
7
votes1
answer436
viewsA: How to shuffle string list in c#?
Use the class Random. It makes a simple but effective randomization. Example: List <string> ListaFrases = new List<string>(); var rnd = new Random(); // Randomizador // Cria uma nova…
-
5
votes1
answer580
viewsA: Pass Parameters to Store Procedure
There is yes, the correct is this syntax (using your code as an example): var result = context.Database.SqlQuery<Pessoa>( "SP_Busca_Cliente @Nome", new SqlParameter("@Nome", nome)); You do not…
-
0
votes1
answer116
viewsA: Configure Multiple Windows Services in a Single Project
The solution to this case is very difficult to find, but I think I found it here, I’ll explain to you. first - Create a class Installer, it should be public, not static, inherit from Installer and…
-
3
votes1
answer325
viewsA: Where to place asynchronous request methods following ASP.NET MVC standards?
Yes, it is in the view controller that the methods if request should be, either synchronous or asynchronous. Following the premise of Soc (Separation of Concerns), his Controller shall contain only…
-
6
votes3
answers663
viewsA: Class generic property
What you requested can be done with dynamic or object. Example: public class Field<TValue> { public string Name { get; set; } public TValue Value { get; set; } public Field() { } public…
-
0
votes3
answers2857
viewsA: How to make a string in Appsettings and use it later
In his app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="exemplo" value="exemplo"/> </appSettings> </configuration> In…
-
0
votes1
answer112
viewsA: Passing array list by parameter
The syntax to convert your byte array list to a two-dimensional byte array should be this: byte[][] listaEmByte = listaDeBytes.SelectMany(a => new byte[][]{a}).ToArray(); Or if you want to remove…
-
4
votes1
answer70
viewsA: Is it possible to create a class from a Forms opening routine? How?
It is possible using Generics. You create a generic method that receives a Form, the method knows it is a Form, then you can manipulate him. The code becomes much simpler. Generic Method: public…
-
2
votes1
answer136
viewsA: Error editing record more than once with Entityframework C#
The context of the Entity Framework stores (cache) the entities you previously manipulated. When you try to enter/change an entity that already exists, it gives this error because it is in memory…
-
2
votes4
answers316
viewsA: Is it bad practice to make this comparison?
As for performance, it’s practically imperceptible to human eyes, maybe it’s in benchmarking tests. But unless you are writing code for life support (medical area) or other area where response time…
-
3
votes1
answer64
viewsA: Relationships with the Entity Framework?
Using this tutorial as a reference, there may be two types of configuration. Option 1 - Data Annotation public class Aluno { public Aluno() { Professores = new HashSet<Professor>(); } public…
-
3
votes1
answer432
viewsA: How to map a List to another List?
Use the Select in the list, it designs a new type from the current type. Example: List<DetalheViagemDto> viagens = detalheViagens.Select(t => new DetalheViagemDto { Prop1 = t.Prop1, Prop2 =…
-
1
votes1
answer340
viewsA: How to use Asnotracking when working with Repository
I believe you’re encapsulating the method Find of the RU behind this method ObterPorCodigoEvento. If that’s the case, there is no AsNoTracking to Find, what you can do is: // Estou chutando que a…
c#answered MurariAlex 2,150 -
1
votes1
answer45
viewsA: Enable tab in Readonly = true fields | Visual Studio
To the TAB not focus on the element use: txtMeuControle.TabStop = false; Even so it will still be possible to click and select the control, not to be able to click the control, probably only…
-
1
votes2
answers41
viewsA: Connect to SQL with Appconfig
In his app.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="MinhaConnString" connectionString="Data Source=SQL;Initial…
-
2
votes3
answers335
viewsA: Dynamic path C#
In this case you want the physical path, which is a path at the system level ("D: Blabla..."). Do so (using HttpRuntime.AppDomainAppPath ): string arquivoImagem =…
c#answered MurariAlex 2,150 -
1
votes1
answer155
viewsA: Conflict when opening multiple screens in the menuStrip - Visual Studio
Your foreach is trying to cast a cast on all open forms, this will give Exception because there are other types of open forms that are not of the type frmCadastroServico. Use the OfType<T> in…
-
0
votes2
answers28
viewsA: How to intercept the project save event on vssdk?
According to this link from MSDN, you need to create object references Events and DocumentEvents, otherwise they will be collected by Garbage Collectorand will be rendered useless. Example: private…
-
4
votes1
answer2621
viewsA: How to call the form inside another - Visual Studio
You need to set the parent form (Parent) of your new form: Example: frmCadastroServico CadastroServico = new frmCadastroServico(); CadastroServico.StartPosition = FormStartPosition.CenterParent;…
-
1
votes1
answer26
viewsA: How to work with Datagridviewcheckbox using a chekBox apart that allows enabling and disabling all Datagridview fields?
I changed your code to take into account the value of your checkbox that plays the role of "select all". It is to work properly now; foreach (DataGridViewRow row in dgv_Entrada.Rows) {…
c#answered MurariAlex 2,150 -
7
votes2
answers391
viewsA: What’s the Where for?
You have a collection of numbers. List<int> numeros = new List<int> { 1,2,3,4,5 } You want a new collection with only even numbers from your otiginal list var numPares = numeros.Where(x…
c#answered MurariAlex 2,150 -
2
votes1
answer28
viewsA: How to work with Datagridviewcheckboxcolumn in c#?
The code is wrong. You’re iterating through all the lines of your datagridview and after you’ve gone through all and arrived at the last you’re called the method obj.Actualizar; that is, it will…
c#answered MurariAlex 2,150 -
0
votes1
answer616
viewsA: How to perform sum per line on a datagridview in c#
With LINQ it feels really good to do it, and simple. decimal totalEuro = DGW_PedComprasPic.Rows.Cast<DataGridViewRow>() .Where(t => t.Cells[/*Nome ou indice da coluna com o tipo da moeda…
c#answered MurariAlex 2,150 -
3
votes1
answer178
viewsA: Generic Class Receiving a Generic List>?
There is, just use it type parameter constraint. Placed object in the generic list type, change to your need. Example: public class Negocio<TEnt, TDto, TDao, TList>() where TList :…
-
3
votes1
answer2023
viewsA: Change color line according to cell content in datagridview
You will iterate through all the lines of your DataGridView and compare the value of the column that contains the value you want to check. If the value is negative, the line (Row) will be painted of…
c#answered MurariAlex 2,150 -
1
votes2
answers75
viewsA: Conversion of bank image to use in a background
- For images saved in the database as Base64 - I believe the image was saved as an array of bytes (data format). So, do it this way: Put this method in some helper class or inside your code-Behind…
-
1
votes1
answer59
viewsA: Dependencies with Entityframework C#
Do so (Entity Framework 6): using System.Data.Entity; private void FrmCidade_Load(object sender, EventArgs e) { var registros = Contexto.Cidades.Include(e => e.Estado.Select(y =>…
-
2
votes2
answers324
viewsA: What is the correct way to use Runonuithread() in Xamarin.Android?
Yes, it is necessary. Components declared and displayed in the UI live in the UI and are operating in the thread ui. Accessing these components from another thread would violate thread-Safety. That…
-
1
votes1
answer94
viewsA: Methodinvoker does not update listbox C#
The listbox notes changes in the object you are passing to the property Datasource, setting the same object does not help, the object itself has to be modified. One solution is to use the class…
-
-1
votes2
answers753
viewsA: Daylight saving time with old dates
If you are sure which zone the time was created in, you can use this method: public static DateTime ConvertToBrazilianTime(DateTime utc) { return TimeZoneInfo.ConvertTimeBySystemTimeZoneId (utc, "E.…
-
3
votes1
answer134
viewsA: Elapsedeventhandler syntax in System.Timers.Timer
It’s called Method Group Conversion, functionality included with C# 2. In C# 1, you had to write the constructor of delegate passing as parameter the action (action) that delegate.…
c#answered MurariAlex 2,150 -
8
votes2
answers245
viewsA: How to fire multiple exceptions?
If you really want to throw several exceptions at once for the code caller, use the class AggregateException, she gets a list of Exception. I adapted your code as example: List<Exception>…
-
1
votes2
answers585
viewsA: Jsonresult display Displayname from an Enum
Try this, considering you’re using the library Newtonsoft.Json: [JsonConverter(typeof(StringEnumConverter))] // Adicione isto public enum TipoPessoa { [Description("Pessoa Fisica")] [Display(Name =…
-
1
votes3
answers39
viewsA: Cast error while running the Rest service
In SQL the type float is equivalent to double. No. NET the nickname (alias) float is equivalent to single. C# Reference So, apparently in your database, the column Qtde is float but in C# should be…
-
2
votes3
answers4858
viewsA: How to write a date in ISO 8601 type
Option 1: DateTime.UtcNow.ToString("o"); Option 2: DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"); Option 3 (with the specified used format):…
-
2
votes1
answer67
viewsA: Totable method is not recognized
Install this package: Microsoft.EntityFrameworkCore.Relational These methods belong to him.
-
3
votes1
answer107
viewsA: Beginform from ASP.NET does not apply route mapping when making the request
The problem there is that the route systems choose the first compatible route to build the route and not the custom one. To specify a custom route, use the method Html.BeginRouteForm(). In it you…
-
26
votes3
answers8582
viewsA: What are Parallel.For and Parallel.Foreach loops?
Imagine you have a directory on your computer with 8 music files in FLAC format. Excellent format by the way, clean audio. Now imagine that you want to convert these files from FLAC to MP3 (not so…
-
4
votes1
answer1351
viewsA: Multiple inheritance and diamond problem
If a class inherits two classes (concrete implementations), there may be conflict of implementations. Example: class ClasseBase1 { public void Foo() { Console.WriteLine("ClasseBase1"); } } class…
-
0
votes1
answer1082
viewsA: Check items registered in the checkedlistbox
First you need to get the content of the CheckedListBox you need to edit. For ease, I am assuming that you want to get the item from CheckedListBox by its name (label). Use this code: private int…