Most voted "c#" questions
This tag should be used when the question refers to some resource, information or problem related to the C#language. C# ("C Sharp") is a multi-paradigm programming language that has strongly typed variables, is imperative, declarative, functional, generic, object-oriented and component-oriented, which are designed to be executed in . NET Framework.
Learn more…13,899 questions
Sort by count of
-
3
votes0
answers44
viewsWhat is the parameter "in" in a generic type in C#?
I came across a C# scenario that I didn’t quite understand. I was studying and I saw a code piece with a generic type that has the reserved word in for that guy. What would be the purpose of using…
c#asked 5 years, 9 months ago Pedro Paulo 3,651 -
3
votes3
answers2862
viewsChanging data from a List<>
Hello I have a collection like this made on top of a class: public class Produto { public int Id { get; set; } public string Descricao { get; set; } public int Quantidade { get; set; } public…
-
3
votes1
answer198
viewsAuthorizeattribute in Controlller and Actions
When using an attribute (Authorizeattribute) developed by me (with use of Enums) it is not working as it should as follows: When used to memorize the Controller statement:…
-
3
votes2
answers81
viewsHow to get multiple Abels to have a randomly generated number
I am playing a Bingo game. Where I have 4 cards and each card has 15 Bingo cards (15 numbers). I want that when the form starts, each label has a randomly generated number. However, I’m only getting…
c#asked 5 years, 8 months ago D. Rodrigues 79 -
3
votes1
answer512
viewsError: Cannot convert Implicitly
I’m getting the following error. It is not possible to implicitly convert "System.Linch.Iqueryable" to "Testemercos.Models.Applicationproduct". There is an explicit conversion ? in that part of the…
-
3
votes1
answer459
viewsRun log method whenever Exception ASP.NET MVC (Exception Handling) occurs
I need to implement Error Log in my application ASP.NET MVC, My question is the following, is there any way I could trigger a method (This would be a method that would save the error log, send the…
-
3
votes2
answers347
viewsIgnore a specific Exception
In my try-catch, I want to record the exception that occurred within an object (for historical effect, necessary for the business rule, since this section takes place in a processing via integration…
-
3
votes1
answer291
viewsWhat’s the Context class for?
I am developing a system in ASP.NET MVC with mapping using the Entity Framework, when observing some patterns I see a lot the use of the class Context, what it’s for and what it should contain…
-
3
votes1
answer501
views-[Lifestyle Mismatch] Applicationsigninmanager (Web Request) depends on Iauthenticationmanager (Transient)
I’m getting an error on startup simpleinjector which I cannot solve at all. The error appears when it tries to run the line: container.Verify(); Follows error: -[Lifestyle Mismatch]…
-
3
votes1
answer412
viewsClass attribute with predetermined values
I want to create a class attribute for sex (M or F), that by default one can already select. It is possible to create an array with these values (M and F) already default without having to type, or…
-
3
votes2
answers64
viewsDoubt with string, extract data
I have the following string [{"tipo":"simnao","pergunta":"rwerwerwerewr ?","tag":"#acimadopeso","resposta":"","$$hashkey":"object:410"},{"pergunta":"werwerwerwer…
-
3
votes1
answer109
viewsIs it feasible to migrate from long to Guid?
Using Webapi, . NET Standard, C#, Entity Framework - Codefirst The records in long may exceed their limits. It is feasible to change long for Guid the primary key with the populated bank and running…
-
3
votes4
answers961
viewshow to generate an xml in memory
With the code below, I Gero a file and write somewhere, however, instead of writing to the disk, I wanted to generate in memory, as it does? using (var context = new…
-
3
votes1
answer184
viewsWhat is the difference between arrays vs. Collections in C#?
Concerning arrays and Collections in C#, vary from application to application or there is unanimity between them?
-
3
votes0
answers44
viewsHow to update classes at runtime? EF C# MVC
I need to update my application’s classes because it has a function in my controller that creates a new column: public string ListarMapeamento() { banco.Database.ExecuteSqlCommand("ALTER TABLE…
-
3
votes1
answer44
viewsPage inside a Rest Web Api C#
Hello. I am creating a . Net Core C# Rest project, but I have the following question: In the processing of the Rest Post, I will return a URL so that the requesting one can view the result data it…
-
3
votes1
answer44
viewsUndo Editingcontrolshowing
I have a Datagrid in which a certain column can only be inserted numbers, so I used "Editingcontrolshowing" to evaluate the user input in this column and only allow numbers. string columnName =…
c#asked 7 years, 8 months ago Antonio Rafael da Silva Filho 199 -
3
votes1
answer114
viewsDetect date change in Windows [C#]
I would like to know: How can I detect and display a warning to the user through a MessageBox, whenever my application is running (is maximized or minimized) and the date of the computer is changed?…
-
3
votes2
answers425
viewsAsynchronous alternative to Thread.Sleep without locking application in C#
Sometimes we want our application to wait a few moments to proceed with the next instruction, however the Thread.Sleep(0) can cause crashes in your application, mainly using in loops. So here’s a…
-
3
votes1
answer666
viewsHow to make Join with more than two lists?
I have three classes: class Cbo { public string ProfId { get; set; } public string Cbo { get; set; } public string Descricao { get; set; } } class Profissional { public string ProfId { get; set; }…
-
3
votes1
answer137
viewsEntity Framework returns any type of data with Sqlquery
I’m trying to return dynamic values of a query also dynamic, but I can’t figure out how to get any kind of data from the database. Here’s what I’m trying to do comandoSql = @" SELECT " + NomeCampo +…
-
3
votes1
answer446
viewsC# - CPF Mask
I’m looking to put a placeholder effect on a masking text box. The idea is to activate the CPF mask as soon as it enters the text box and disable it if the text box is empty when exiting. private…
c# textbox desktop-application mask placeholderasked 5 years, 6 months ago Pedro Henrique de Lima 33 -
3
votes1
answer1959
views -
3
votes3
answers297
viewsConcatenate and convert string array into int
I can’t put together all the numbers in an array, I’m not talking about adding, but concatenating, and converting into an integer. See the example: ex: string[] matriz = new string[3]; matriz[0] =…
c#asked 5 years, 6 months ago Davi Mendonça 33 -
3
votes1
answer772
viewsCheck if a string is a valid date
How do I check whether the date is valid in C or not#? In VB6 I did like this: If Not IsDate(strAux) Then In the case of C#, how do I? My code in C#: //Data Movimento string strTxt =…
-
3
votes0
answers67
viewsLoad information inside the lambda and use in lambda foreach
I created a property in the class CatalogItemResponse to use in a method, but Boss asked to take it. It turns out I need it to load another property and without it I’m not getting it. This is my…
-
3
votes1
answer59
viewsDelete characters from a string
Hello, I have the following code snippet: agenciaModel.Bcx_Nome = agenciaViewModel.Bcx_Nome; to agenciaModel is sent to the api and sent to the banco de dados, but in the database the maximum string…
c#asked 5 years, 6 months ago Jeff Henrique 1,020 -
3
votes1
answer1323
viewsCS0116 C# A namespace cannot directly contain members, such as fields or methods
Good afternoon, I am using VS17 C# and copied the command of another project and is giving error: CS0116 C# Um namespace não pode conter diretamente membros, como campos ou métodos error line:…
c#asked 5 years, 6 months ago Thiago Mazette 45 -
3
votes1
answer285
viewsFill Grid dynamically with Dapper framework return
I have a screen written in VB.NET Winforms, where the goal of it will be to execute SQL commands without the need to open a sql studio. For simpler commands like delete, update, alter table among…
-
3
votes1
answer1058
viewsThere is a difference between private void, public void, public bool, public string, etc. Can someone explain this to me?
Until now to create functions in c# it was rare to use the public bool to create functions, used more the private void and the public void. I was looking at a tutorial where he used for example:…
c#asked 5 years, 5 months ago Gonçalo Sousa 103 -
3
votes1
answer49
viewsCan anyone explain to me why this mistake?
Code: int jogo = 0; public void ganhou() { MessageBox.Show("O jogador " + jogador_atual + " ganhou!"); reniciar(); jogo++; lb_numero_jogo.Text = Convert.ToInt32(jogo); } Error: Cannot implicitly…
c#asked 5 years, 5 months ago Gonçalo Sousa 103 -
3
votes1
answer485
viewsPass the (integer) Return from a Controller method to the View
I have this method in a controller: int GetSpot() { List<CompanyDetail> topCompanies = GetTopCompanies(); CompanyDetail topCompany1 = topCompanies.Where(x => x.Company.TopCompany ==…
-
3
votes2
answers291
viewsPerform another action during a await Task.Delay
I’m making an application where comes a certain part of the code I need to put a: await Task.Delay(tempo); But at the same time I have to wait around this time I need execute an action every 10…
-
3
votes3
answers121
viewsusing of the unnecessary visual studio
Does anyone know why it gets like this? It shows that using is not being used, but I do not understand why it is not recognized if I am using in the function below. Resolution: using System; using…
-
3
votes1
answer141
viewsWhat is the difference between Strategy Pattern and Specification Pattern
I’m implementing a app CLI in C# of old game and wanted to know which is the best Pattern to use to make the "AI" that would be the player vs computer in the case. I’ve been looking at some Patterns…
-
3
votes1
answer567
viewsUnity3d: How can I move Gameobjects from the same script independently?
I created a script in Unity3d that makes a GameObject move in a sinusoidal way. The movement occurs perfectly, but when more than one GameObject containing this script is on the scene all move like…
-
3
votes2
answers1194
viewsFill a Datatable from a list of a complex type
I’m looking to create a method that gets a list of some kind of complex List<T> and return a datatable with all the data. In my code I managed to get here. protected virtual DataTable…
c#asked 7 years, 7 months ago Matheus Saraiva 2,157 -
3
votes1
answer71
viewsRead something after a C#keyword
I have the following situation, I have a document(txt) that has some things 'filled' type: Nome:"João"; Idade:"20"; Estado:"SC"; The result I wanted is that the variables had only what is written…
-
3
votes2
answers649
viewsProblem with connection between EF and Postgresql
I am trying to make a connection with EF and Postgresql in an Asp.Net Mvc application I am using the following references Entityframework6.Npgsql Npgsql 3.1 .NET Framework 4.5 I have the following…
-
3
votes1
answer125
viewsMemberwiseclone of aggregates
I have in memory (not yet stored in database) an object of type List<NotaFiscal>. I need to pass an item from this list as a parameter to a screen to make changes to that object. However it…
-
3
votes2
answers582
viewsNavigation with Xamarin Forms standard MVVM
I recently started studying Xamarin Forms. I have a question that can be clarified here: how to navigate between pages using MVVM? Navigation should be on vm or in the view? Example <?xml…
-
3
votes1
answer4100
viewsThe ADO.NET Provider with invariant name 'Mysql.Data.Mysqlclient' is either not Registered in the machine or application config file
I have an MVC project, and I wanted to connect to the Mysql database. I put this connectionStrings. <add name="Contexto" connectionString="server=127.0.0.1;User…
-
3
votes3
answers279
viewsRegular expression to ignore quote separator
I have to read a csv file with delimiter ;. Only it has lines with values """Analize;Distribuição""", only that it creates another column in this ;. How can I read so he won’t accept ; in quotes as…
-
3
votes1
answer122
viewsC# How to change value within Parallel.Foreach
I am performing a processing inside an array of strings (lines of a file . txt). For performance reasons, I’m using the Parallel.ForEach, but there was a need to change the values of some lines that…
-
3
votes1
answer247
viewsConvert SQL to LINQ
How do I convert the SQL below to LINQ? SELECT `clientes`.`Nome`, `clientes`.`Cpf`, `clientes`.`email`, `clientes`.`Id` as clienteId, `cartoes`.`Id` as CartaoId,…
-
3
votes2
answers590
viewsHow do I receive a value for each double variable on the console?
I was making a very simple code and I didn’t want to type a number and then enter it and then enter another number in another line, I wanted to know if I can do it in the same.…
-
3
votes1
answer427
viewsFormat String after it is converted from HTML
I made a code that turns all HTML into a String, however, when doing this the code is coming like this: <div class=\"page\">\r\n<div class=\"bloco\">\r\n <table id=\"canhoto\">\r\n…
-
3
votes1
answer835
viewsWhat is causing Malformad Reference Element in my Signature?
I am trying to sign an XML by passing the tag reference, id, XML and certificate. In a certain situation it doesn’t work, however I never know what situation this is, it is something kind of random.…
-
3
votes1
answer69
viewsHow to identify the Entity that throws the error when saving?
In my application, with Entity Framework, I make a query in a Round entity: var lista = contexto.Rodada.Where(condições); Then I’ll go over that list with a foreach. During iteration "updates" and…
-
3
votes1
answer121
viewsIterate an array (vector) via Ienumerator? For what reason?
In which case it would make sense for me to give up iterating a array using loops "normal" (for/foreach/while) via index to use the IEnumerator as shown in Example 3? Example1 //Usando for int[]…