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
-
6
votes3
answers155
viewsHow to test Filters that verify Claims data?
I own a ActionFilter for some controllers and actions that make use of the user information that are in Claims. The filter itself obtains information from Claims user and executes the authorization…
-
6
votes1
answer289
viewsDropdown filter using C# MVC 4
I have a dropdown in my view that I fill in the following way: ViewBag.NfeStatus = EnumHelper .ListAll<NfeStatus>() .ToSelectList(x => x, x => x.Description()); My model Nfestatus is an…
-
6
votes1
answer406
viewsAuthorization in Asp.Net MVC
I’ll try to be clear. In most examples of ASP.NET MVC authentication and access authorization, I see that authorization control is usually done on Controller, with the decoration of the class itself…
-
6
votes3
answers178
viewsHow to capture a Nullreferenceexception?
When I test my application, it returns some specific data, but when the requested data is null, this untreated exception error appears I tried to capture him but I think I’m making a mistake. How…
-
6
votes1
answer1271
viewsRelationship Problem Many to Many in the Entity Framework
I have the following situation: To perform an authentication, I’m using the old method for a small application, for assigning levels (roles), as many examples are found all over the web. Use EF and…
-
6
votes1
answer111
viewsCan LINQ be considered business rule?
Sometimes I pull active objects with LINQ expression. Utilise filtering with LINQ can be considered a business rule and in a scenario such as DDD (Domain-Driven Design)? What is the best place to…
-
6
votes1
answer1327
viewsCan’t find Httpcontext.Current
I’m trying to create a Urlhelper as follows: UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); I already made the reference to System.Web, as I saw as solution in…
-
6
votes1
answer1657
viewsEntity Framework - What is the difference between With Entitystate.Modified and Without Entitystate.Modified?
What’s the difference between the two ? With Entitystate: var registro = db.MinhaTabela.Where(a => a.MeuCampo == "Valor_Antigo").FirstOrDefault(); registro.MeuCampo = "Valor_Novo";…
-
6
votes1
answer561
viewsProblems Xamarin Asynchronous method
In the event of a button of my APP had the following code it worked running on the android emulator, but when I passed the app to the mobile generates a message the app stopped. Button…
c# wcf xamarin asynchronous xamarin-studioasked 8 years, 10 months ago Diego Filipe Pedro Santos 531 -
6
votes2
answers644
viewsArc tangent function in C#
I did the following calculation on the calculator: arctg(50/10) = 78,69° However, when doing in the code, using the function Math.Atan, the result is as follows: Is there any other way to calculate…
-
6
votes1
answer185
viewsQuery Linq and see index
He wanted a query in Latin that shows the attributes of the availability table and the name of the respective catechist that is in the person table. At index will appear: Nome | AnoPastoral |…
-
6
votes2
answers2918
viewsEntity Framework WITH (NOLOCK)
We can use the NOLOCK in the SELECT, thus avoiding the blockages with the commands of INSERT SELECT COUNT(Descricao) FROM Produtos WITH (NOLOCK) Is there any way to use the WITH(NOLOCK) in the…
-
6
votes1
answer1209
viewsSoftware license registration file issuance and control
I have a system to control and issue electronic license registration files, so I have control of how many machines my software can run. My teacher advised me to use the CPUID processor to validate…
-
6
votes1
answer131
viewsCopy DLL to directory with . nuspec without referencing it in project
I created a local Nuget. It worked fine until we found a problem that I can’t solve right away. The following: There is a reference in the project, which calls another reference. Well, it turns out…
-
6
votes3
answers284
viewsWhat should I observe when creating a hash code?
Still talking about the reply about hash code it was not clear what should be observed to produce good hash codes. I understood that it needs to be a number that doesn’t generate a lot of…
-
6
votes1
answer5562
viewsDisplaying message in a view through the C# MVC Controller
looking for a solution I found a way in the link Controller message to view But my problem is that nothing is shown. I don’t know if it’s because I don’t have an action in the View but the message…
-
6
votes1
answer326
viewsHow to create a monolithic application executable. NET?
I wouldn’t want to do the deploy from the full DLL application, wanted something simple, no installer, wanted to generate only one executable file, but the . NET is all DLL-based. You can generate a…
-
6
votes1
answer325
viewsRun Insert in Migrations Entity Framework
I am developing an ASP.NET MVC project with Entity Framework Code First. I already checked the bank and managed the first Migrations, my question is: has how to execute a insert right after creating…
-
6
votes1
answer84
viewsHow to start a variable correctly?
There is a difference between these two ways to start a variable? List<classeterapeutica> itens = new List<classeterapeutica>(); modelOff.classeterapeuticas.ToList(); or…
-
6
votes1
answer155
viewsModeling with Code First so you can exchange databases
If I generate my database for Mysql using the concept of Code First is it possible to change it to SQL Server in the future with relative ease? Need to change the classes or just the config and the…
-
6
votes1
answer439
viewsAdd grid data to database
I have a loan screen and in it I have a datagrid with a checkbox selection and I would like to add in the database only the line selected by the user, as I can do? Loan screen code: using System;…
-
6
votes3
answers4491
viewsHow to check if the program is already running in C#
I wonder if there is a way to check if there is already an instance of the running program, so that if I click the program icon it does not call a new instance of the program but open the already…
c#asked 7 years, 5 months ago Victor Freitas 738 -
6
votes2
answers2059
viewsUpload Image Asp net MVC
My question is this: imagine a scenario where I have a canvas that has a form, and in this form also exists upload images. Let’s assume that I fill out the entire form, and select 3 images in the…
-
6
votes2
answers665
viewsWhat is the maximum size of an object in 32 and 64 bits?
Specifically the array can have up to 4 billion elements, I think, and the most common sizes of elements should be 4, 8 or 16 bytes. I ask, what is the maximum size that the object can occupy in…
-
6
votes1
answer140
viewsDynamically use LINQ aggregator
I am trying to create a function to use Linq aggregator functions (sum, Average, Count) and I am not succeeding. I have the following code: private double…
-
6
votes1
answer83
viewsIs there any way to be notified that there will be a garbage pickup?
I’m studying about the Garbage Collector do . NET and wanted to know if there are any events that I can sign and be aware whenever a collection will be made.
-
6
votes2
answers1833
viewsCreate objects without reference C#
My question is, I have two instance of the class Parents, faths1 and fathers2, I created the 3 instance of the class Parents called fathers3 and said that it will be equal to instance fathers2,…
-
6
votes0
answers1142
viewsSigning Nfs-e in C# generates error Poorly formed Reference Element
out of nowhere my code in C# stopped signing the Nfs-e of Curitiba. In the code line below, gives the error: signedXml.ComputeSignature(); Errro Elemento Reference mal formado Does anyone know if it…
-
6
votes1
answer98
viewsWinform - Tabcontrol bug with Metroframework
So I’m having a little problem when I use Tabcontrol customized by Modern UI Metroframework. It turns out that a bar appears on the upper left (scroll bar) and only disappears if I click on it. Ex:…
-
6
votes1
answer2702
viewsHow to extract and compress files with System.IO.Compression.Ziparchive in c#?
I’m starting in C#. I saw that there’s class System.IO.Compression.ZipArchive to work with zip files. I have some doubts: How do I unzip an existing zip via Ziparchive? How do I compress to an…
-
6
votes1
answer2378
viewsWhat are the differences in performance when using querys with EF vs ADO
What is the difference in performance when using the basic query methods SqlQuery<TElement> and ExecuteSqlCommand of Entityframework in relation to directly using the ADO.NET? If there is…
-
6
votes1
answer231
viewsWhat are they for and when to use the Preprocessor directives?
Some time ago I had seen the use of #define in C#. Today I searched about it and found its documentation here, but did not answer all my doubts. Code example with Preprocessor directives: #define…
-
6
votes2
answers199
viewsHow to popular a model from a Datareader in C#?
I’m sorry I was so ignorant about that question. In PHP there was the possibility of using the "Fetchclass" of PDO that took all the results of a table and threw them in an object of a certain…
-
6
votes2
answers1292
viewsXamarin Error - aapt.exe/Resources
I installed Visualstudio 2015 Community, with Xamarin, until then beauty. But I’m in trouble, actually not only myself, I’ve seen in many places, that quite a lot of people are making the same…
-
6
votes2
answers195
viewsInserting single quotes into null fields
I created a very simple application to simulate a small client registration, but when testing the manipulation of data by the application I could see in the database that the fields that are null in…
-
6
votes3
answers1767
viewsAttribute in Dataannotations for Currency
I would like to format with Dataannotation currency but standard in the model: [Column("cur_mensalidade")] [DataType(DataType.Currency)] [DisplayFormat(DataFormatString = "{0:C0}")] public decimal?…
-
6
votes2
answers6436
viewsClass, Superclass and Subclass
Regarding inheritance by code reuse in C# I have the following doubt: What’s the difference between classes, superclasses and subclasses? This changes something when doing code reuse? Additional…
-
6
votes1
answer100
viewsWhat is the use of default interface methods?
I was seeing some features proposed for C# 8 and came across the default interface methods. Add support for virtual Extension methods - methods in interfaces with Concrete implementations. From what…
-
6
votes1
answer4952
viewsHow to update a datagridview automatically?
I created an application that will display the data of a particular view in a control datagridview. The entire application is already ready: the data upload, the update button and also the events…
-
6
votes1
answer283
viewsHow to edit data (just numbers) and calculate their values on a Datagrid?
I need a Datagrid column to receive from users only numbers in rows (cells) and that after clicking the button, multiplication calculations are performed between cells of the same row and different…
-
6
votes2
answers1839
viewsSwitch Alternative Inside Switch
I’m making a decision structure that depends on more than one variable, but readability and maintenance using if or switch are terrible. What alternatives do I have for this case? Example of switch…
-
6
votes3
answers2216
viewsHow to reverse an integer?
Note this statement: /* * Faça um programa que peça um numero inteiro positivo e em seguida mostre * este numero invertido. Exemplo: * o 12376489 * => 98467321 * */ Console.Write("Informe um…
-
6
votes1
answer288
viewsError using Entity Framework Bulkinsert
I have an Asp.Net MVC project in . Net Framework 4.0 with Entity Framework 5.0, where I added the Bulkinsert-ef5, but in the following excerpt error occurs: using (MeuEntities context = new…
-
6
votes2
answers1543
viewsHow to select fields in a lambda expression query?
Through the select new from LINQ I can select which fields will be displayed in the query, for example: var subCategorias = from s in db.SubCategoria join c in db.CategoriaProduto on s.id_categoria…
-
6
votes1
answer480
viewsIn a C#console program, where is the main class set?
I’m doing my first console program in C#, just to do some tests. I have two classes: HelloConsole.MainClass and HelloConsole.Calc. I have the following code: using System; // Aprendendo o alias de…
-
6
votes3
answers364
viewsDrag and Change Position of a Groupbox at Runtime
I have a groupbox that I wish the user could drag and change the position at runtime, someone imagines some way to do this?
-
6
votes1
answer145
viewsWhat are dynamic properties?
I am studying ASP.NET and saw the following code snippet: ViewBag.QtdNovosComunicados = (from c in comunicados where c.DataCadastro > UsuarioLogado.dtUltimoAcesso select c).Count(); I understand…
-
6
votes1
answer73
viewsMeaning of expression <%# "example" %>
I’m used to seeing expressions like <%= "Olá" %> but I came across a code: <asp:Image id="imagemStatusDocumento" runat="server" ImageUrl='<%# ObtemImagem(Eval("NomeTipo")) %>' />…
-
6
votes1
answer430
viewsRandom always returning the same number
I have a method that its function is to return 25 random numbers on a list: static List<int> criarList() { List<int> lista = new List<int>(); for (int i = 0; i < 25; i++) {…
-
6
votes2
answers283
viewsModifying a list item shared by multiple threads
I have the following pseudo-code: public void Associar(List<Data> dados) { List<Task> tasks = new List<Task>(); foreach(dado in dados) { tasks.Add(AdicionarAsync(dado)); }…