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
-
5
votes1
answer349
viewsDoes Task.Run always start a new Thread?
When executing a list of tasks initiated through Task.Run, it is ensured that each one is executed in a different Thread? When reading the documentation, it seems to me that this is the default…
-
5
votes4
answers2109
views"Filter" equal records into a list by adding their quantitative
namespace ConsoleApplication10 { class Program { static void Main(string[] args) { List<Teste> lstTeste = new List<Teste> { new Teste {Codigo = 1, Quantidade = 10}, new Teste {Codigo =…
-
5
votes1
answer356
viewsHow to change the template(visual) of an Asp net mvc5 page according to user
Here’s the thing, I need to read a property that returns me 1,2,3... and with it I determine what kind of visual the page will have, template01,template02... how I would do this using areas, and…
-
5
votes2
answers1642
viewsHow do you convert an Enum guy into a list?
Is there any way to convert a Enum in List? public enum TiposHospedagem { Casa = 1, Hotel = 2, Pousada = 3, CasaCampo = 4 } I’m trying to run the enum and add to the list, but the foreach does not…
-
5
votes2
answers109
viewsQuestions about Fluent API relationship for EF 5
I have two classes: User > Contains your PK (ID). User > Contains the user ID(FK). Class User.Cs public Usuario() { this.UsuariosP = new List<UsuarioP>(); } public int Id { get; set; }…
-
5
votes2
answers4659
viewsComparing only the Datetime field date in C#
I only need to compare the date of two fields DateTime. DateTime aux = new DateTime(2016, 09, 02, 10, 0, 0); if (aux.Equals(DateTime.Now)) { //Alguma ação... } In the code above, I need you to enter…
-
5
votes5
answers5699
viewsHow to get the current iteration index of a foreach?
Usually in order to get the current iteration index within a foreach, I do it this way: int i=0; foreach (var elemento in list) { // Qualquer coisa i++; } I believe there are other methods to get…
-
5
votes2
answers395
viewsBehavior of parameters in the class constructor in C#
I have a question regarding the behavior of the parameters passed to the constructor of a class, they are by default ref/out or value? Searching on the behavior of parameters in common methods they…
-
5
votes5
answers29254
viewsHow to convert date to dd/MM/yyyy format?
After I published my app, I started to receive the dates in the American format like this:9/14/2016 12:00:00 AM How to format to dd/MM/yyyy? I tried to convert.ToDateTime() more does not work.…
-
5
votes2
answers24321
viewsThe SMTP server requires a secure connection or the client has not been authenticated
I’m having the following mistake, working with SMTP and MailMessage in the C#: The SMTP server requires a secure connection or the client has not been authenticated. The server response was: 5.5.1…
-
5
votes1
answer96
viewsCatch the time on a remote computer using C#
Is there any method for me to recover time and date from a remote computer using C#?
-
5
votes2
answers145
viewsChild references and service Pattern
A widely used Pattern in DDD, is the service pattern. My question is, where is the logic for references "daughters"? For example, a use case, Pedido who owns Produtos public class Pedido { public…
-
5
votes1
answer65
viewsHow to use Bitconverter.Todouble bytes
I have an interface that sends a reference value to a microcontroller. I need to send the values in bytes because these values will be saved in the memory of the microcontroller. On the interface,…
-
5
votes1
answer1179
viewsError entering data into database, EF 6
I’m trying to input data into the database, but I have a mistake in doing the saveChanges(); after doing several times the context.add(), has happened after 500, 2200 and 5500 times. Error: The…
-
5
votes1
answer219
viewsHow to simplify code with Foreach List?
How to use the ForEach() of List in the implementation below using System.Collections.Generic; public class Program { public static void Main() { List<Pessoa> pessoas = new…
-
5
votes2
answers651
viewsDifference is between Backgroundworker and Task.Run()?
Usually when I had to do some operation on background, mainly involving progress bar update or Labels I used to use the BackgroundWorker, with your events WorkerReportsProgressand DoWork. I recently…
-
5
votes3
answers1521
viewsHow to Put Music on Console Aplication with C#
I’m creating a game in C# (Aplication console) and I need to put a background music, as I do?
-
5
votes2
answers2900
viewsCustomize Messagebox in C#
I got the following MessageBox MessageBox.Show("Deseja iniciar a forma automática?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question) I can personalize it? Instead of being the buttons…
-
5
votes1
answer168
viewsIs it normal for APK made in Xamarin Forms, even empty, to be 60mb?
I have tried turning on the Linker, and be the recommended procedures. I wondered if it is normal an apk made using Xamarin.Forms start from 60mb. And if not, what to do to reduce the size.
-
5
votes1
answer83
viewsAllow Multiple Users per Browser
For example, the Google allows you to maintain n accounts of Google wrinkled in your browser. In the case of Google, it creates a call control variable authuser who receives a inteiro, it passes…
-
5
votes1
answer1942
viewsError when running test project
I added a test project to my Solution to test the methods of my MVC application. I created a base class, for the other classes with tests to inherit from it, which contains context creation…
-
5
votes1
answer1843
viewsTempdata C# doubt with MVC
I know that the TempData has its "life" maintained until it is used in the View. However, if I do it on two different controllers, the same one identified from the TempData, I’m killing and about…
-
5
votes2
answers987
viewsHow to transform HTML into an image on the server?
I have an Asp.Net MVC project with . Net Framework 4 in Visual Studio, where I need to transform a string with HTML code into image on the server side. I’ve been trying to use that library, but I’m…
-
5
votes2
answers3274
viewsC# - XML return from Webservice with encoding error (ISO-8859-1)
I have a Windows Forms application that is consuming a Webservice that returns an xml (string) enconding with ISO-8859-1. However, the answer comes with question characters (?) instead of accents.…
-
5
votes1
answer203
viewsWhat are the differences between local functions, delegates and English expressions?
Local functions will be present in C# 7. Given this, I would like to know the main differences between local functions, delegates and expressions Amble.
-
5
votes2
answers814
viewsWhat is the most "clean" and clear way to validate entities using the Entity Framework
I am using the Entity Framework for data manipulation. The project is divided into 2, one containing the domain entities and the other the mappings (Fluent Api). I need a clear "clean" way to…
-
5
votes1
answer135
viewsWhen and why use the Obsolete attribute?
At least in the projects I’ve worked on, I see no point in using the attribute Obsolete in methods that are no longer used. What I do, and I see people doing is removing or commenting on codes that…
-
5
votes1
answer1247
viewsStart Windows Service automatically
I created a Windows Service test, I have been researching and saw that to start it automatically you need to change the property StartType of the object serviceInstaller for Automatic, that the…
-
5
votes1
answer549
viewsEntity with multiple members of the same type in the Entity Framework
When we have two entities related to Many-to-Many and create the navigation properties correctly Entity creates an extra table to configure that relationship. In the case I’m working I have a…
-
5
votes1
answer1167
viewsRounding Up - C#
I use a program to correct my stock of the tax file sped that I send to revenue. But I’m in trouble because unit products are coming out with broken value. Example below, the product had (50) units…
c#asked 8 years, 9 months ago Jerrythecat Silva 51 -
5
votes1
answer264
viewsParallelism and Entity Framework
I’m having some problems using parallelism (I don’t have much knowledge in this area) with C# and Entity Framework. My scenario is as follows, I am using an ASP.NET MVC application and within it I…
-
5
votes1
answer633
viewsError executing Databasefactory.Createdatabase() method
I’m getting the following error while performing the function DatabaseFactory.CreateDatabase(): "Configuration system failed to boot" The app.config is as follows: <?xml version="1.0"?>…
-
5
votes1
answer6047
viewsWhat causes the 'System.Nullreferenceexception'?
Time or other the execution of my systems are interrupted by this error, when it happens, a if(atributo != null) It usually does, but it pollutes the code, "Oh, but this variable needs to have a…
-
5
votes3
answers7208
viewsHow to select Digital User Certificate in Web Applications?
I am developing a project in ASP.NET MVC5 to make manifestation of electronic invoices. During the process of searching notes, manifestation or download, I access the Internal Revenue Service and…
-
5
votes1
answer178
viewsWhat is an Appdomain?
I read about it on the Microsoft website. It would be interesting to have a succinct answer here in Portuguese with a summary of what is? There’s something important that’s not in the documentation?…
-
5
votes1
answer596
viewsPersonalize message by the hour
I wanted to personalize the greeting message depending on the time. Ex: Hora menor que 12h. "Bom dia" Hora menor que 18h. "Boa tarde" I did with if and else but wanted a better method. //Pegando a…
-
5
votes2
answers439
viewsEntity Framework | Double property that allows null
My property allows values double and values null. In the SQL Server Database it is set to decimal(18, 2). But when seventh some value (ex: 5.00), makes the mistake below. Error: The 'Rating'…
-
5
votes1
answer546
viewsGet CPU usage of a process in int C#
I need to get CPU usage of a process that is a variable. Ex.: var process = wait.exe And check the Wait.exe, if it has reached 100 CPU usage. How can I do this?…
-
5
votes2
answers62
viewsError sorting list?
ViewBag.ListaEspecialidades = Especialidade.ListarEspecialidades().Sort(); Of a mistake "cannot implicitly Convert type void to Dynamic".…
-
5
votes2
answers350
viewsHow to get the total memory occupied by the application?
I know there’s a GC.GetTotalMemory, but it only shows the consumption of managed memory. It has how to discover the full use of the application?…
-
5
votes2
answers83
viewsWhat is the syncblock?
I received a reply about a syncblock. Why is it necessary? I understand what I researched is about competition control. But why does every object need it if not everyone will have competition?…
-
5
votes1
answer3605
viewsSimple National Opting Query (by CNPJ) - C#
I am implementing in C# a Consultation of Company Opting for the National Simple Tax Regime through this link…
-
5
votes3
answers119
viewsWhy declare property twice in one class?
When declaring a property in one class, they usually declare twice, one public and the other private. What is the purpose? private int _years; public int Years { get { return _years; } }…
-
5
votes2
answers83
viewsDesign based on the VS2015 spa template. How the service is generated
I created a project using the SPA template in Visual Studio 2015, to learn and understand, but I found this example very complicated. I still don’t understand where the service is mounted and…
-
5
votes2
answers744
viewsDeletion of related data - Entity Framework and C#
Hello, Using the same structure that I have been presenting here for some time, I come to ask for help now to delete the related data. Follows the entities.. public class Artista { public int…
-
5
votes2
answers1613
viewsCan cause cycles or multiple paths to cascade. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY restrictions
I have a class that will have two FK pointing to the same table, so Entity Framework returns the error: Can cause cycles or multiple paths to cascade. Specify ON DELETE NO ACTION or ON UPDATE NO…
-
5
votes2
answers3095
viewsHow to pass variables from Controller to View in ASP.NET MVC 4.5?
I’m quite used to PHP MVC where I can pass the values to the view from the controller as follows: public function Index(Users user) { return View('index') ->with('user', $user); } Or to return…
-
5
votes2
answers146
viewsDeclaration of `var as object field
How could I declare a variable var public so that it could take the return of the data. How would the statement of these variables without completion: var tbuscar = ?; var retorno = ?; public bool…
-
5
votes1
answer574
viewsHow does the Type.Invokemember method work?
I came across this method in a code and was curious how it works because I’ve seen some applications running in C# that use this method, and when searching for the method in Google, I found no clear…
-
5
votes2
answers111
viewsControl order causes "System.Nullreferenceexception"
I’m doing some initial tests with the WPF and I came up with this question. Make no mistake: <DockPanel Margin="5"> <TextBox x:Name="myTextBox" DockPanel.Dock="Right" Width="50" />…