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
-
8
votes2
answers1582
viewsVariable of the foreach loop
When we use a loop loop foreach, the local variable we create to receive the contents of the list in question is passed by value or reference? Ex: foreach (var item in listItems) { //TODO } The…
-
8
votes3
answers19310
viewsAlternatives for developing in C# on Linux?
My notebook has installed the Ubuntu 14 operating system. I have great desire to enter the development in the language Csharp. But I wonder if there is a good alternative in OS like Linux, since it…
-
8
votes3
answers852
viewsWeb Security api: SSL?
I wonder if you have how to restrict requests to a web api specifically for a machine. My web api will be hosted on computer A. My client (at first only one) will stay on the computer B. Different…
-
8
votes1
answer356
viewsWeb API and Owin Oauth - redirect to another domain (redirect_uri)
Good afternoon, I’m having a problem implementing external login on a project I’m working on. ASP.NET Web API + Owin + Oauth. Ambience: Work with two Server1 and Server2 servers. Server1: Server…
-
8
votes1
answer1205
viewsDo I need to use Try/catch throughout a process chain?
Supposing I have a call in my layer controller for a method in the business layer that leads to another method in the data access layer. Should I use the try/catch in all of them, only in any or…
-
8
votes1
answer332
viewsNew vs Override
What would be the difference between new and override ? Examples: Override: public class ClasseBase { public virtual void Funcao () { } } public class Classe : ClasseBase { public override void…
-
8
votes1
answer2473
viewsIs it possible to create a site with HTML and C# without ASP.NET?
Is it possible to create a site only with HTML and C#, without ASP.NET? In general, as?
-
8
votes2
answers1094
viewsHow to declare a function within another function in C#?
In Delphi it is possible to declare function within the block of a given function, see this example done in Delphi: procedure TForm1.btnRunClick(Sender: TObject); begin mostrarNome('Carvalho'); end;…
-
8
votes2
answers2267
viewsHow Viewmodel works on Asp.net mvc
I have a similar situation that question where I need to save several models at once and relate each. I would need to sort of cascade to first save one entity and then go saving the others, because…
-
8
votes4
answers835
viewsAssembling updates at runtime
When riding SELECTS at runtime we always have the problem of knowing what may or may not be coming depending on the choices made by the user. When mounting the clause WHERE we come across the…
-
8
votes2
answers563
viewsPrompt Expression<Func<T, bool>> via parameter using object that is in a foreach
I have a model called Entity, this model has links (1 - N) with three other models. public class Entity { // Outras propriedades removidas para brevidade public virtual List<SpecificInfo>…
-
8
votes2
answers927
viewsWhat’s the difference when creating a class libray (.net framework) and class library(.net standard) project in VS2017?
What are the differences and uses of these types of projects?…
-
8
votes2
answers690
viewsHow do I convert PNG to JPG in C#?
I’m working on an old project that uses ASP Site. I need to convert PNG image to JPG. How to do this? Note: I don’t want to rename the file, I want to transform the mime of image/png for image/jpeg.…
-
8
votes1
answer279
viewsWhat is the best type in SQL to use with Cryptocurrency?
I am developing a system where I will store transactions of Cryptocurrencies, type Bitcoin, I can not in any way have problems of conversion and rounding, in C# I checked and the best is decimal,…
-
8
votes1
answer805
viewsController returning partial view in a modal
I have a button on my screen that held call to a method on my controller (Ajax) that returns a partialView by default. $("#btn-Visualizar-Rotina").click(function() { var codUnimetPcp =…
-
8
votes3
answers605
viewsHow to give a Regex before a string? And select?
What I need to do is this: let’s assume that the string is -> :. However I want to select "only" the string before the : using the Regex. To make it clearer: "select that word: another word here"…
-
8
votes1
answer305
viewsImpact of the Garbage Collector
The project here of the company is done in Windows Forms and we do not manage memory very well, because it is a legacy system that has several years running. Currently we are facing problems with…
-
8
votes2
answers291
views -
8
votes1
answer67
viewsWhat is the difference between Class and Code File on Asp.net Core?
What is the difference between Class and Code File in Asp.net Core? There are two types of files in Asp.net core, there is some difference between one and the other? And when we should use each?…
-
8
votes1
answer1041
viewsCQRS - When to use and why to use?
What are the advantages of using the CQRS (Command/Query Responsibility Segregation) standard? What would be the disadvantages ?
-
8
votes2
answers2458
viewsWhat is the purpose of Transactionscope blocks?
I have a code with several blocks TransactionScope and I didn’t quite understand its purpose. ModeloColDataContext dm = DataContextFactory.GetContext(usuario); { if (documento > 0) { using…
c# .net terminology software-engineering transactionsasked 7 years, 11 months ago Marco Souza 12,304 -
8
votes1
answer377
viewsTo automatically fill fields when saving object in database
I have a system, in ASP.NET MVC which implements a form of audit, that when a user enters or updates an object into the database, some information is saved to an audit table automatically. The…
-
8
votes1
answer809
viewsSimple Injector + Uow + DDD + Multiple Contexts + Entity Framework
I need to know how to apply Ioc to two contexts. The scenario is as follows: I have a Layer called Core (allocates classes that I can reuse in other layers), where I put the interface of Idbcontext,…
-
8
votes2
answers1281
viewsGood practices in declaring variables in a for
I’ve been making use of Resharper lately and I’ve enjoyed the experience of using it, but something’s been puzzling me. At times he suggests that certain variables be declared within some scopes, as…
-
8
votes1
answer290
viewsProgressidialog in C#
I’m trying to create a form similar to Progressdialog on android, in C#.. The idea would be that this would happen: //criar o controle na thread principal frmWaitingProgress fl = new…
-
8
votes1
answer324
viewsGet all classes that implement a generic interface
I have an interface similar to this: public interface InterfaceA<T> { T Exemplo(); } And other classes implement it. public class ExemploA : InterfaceA<Int32> { Int32 Exemplo(); } public…
-
8
votes1
answer6294
viewsMultiple INNER JOINS with DAPPER
I’m trying to accomplish multiple INNER JOIN in the Dapper with these classes: public class EventoConfiguracao { public EventoConfiguracao() { //CdEventoConfiguracao = Guid.NewGuid(); Menus = new…
-
8
votes1
answer2537
viewsConsume Webservice Nfedistribuicaodfe - VB.NET or C# - Manifestation/Download Nfe
On the Nfe Nacional website (http://www.nfe.fazenda.gov.br/portal/webServices.aspx?tipoConteudo=Wak0FwB7dKs=) i already have a software made in VB.NET that consumes the WEBSERVICES (NfeConsultaDest…
-
8
votes2
answers114
viewsWhat is the function of Asreadonly() in C#?
I’m studying List in C#, I searched on the internet but still did not understand how it works. List<string> list = new List<string>(); list.Add("Maria"); list.Add("Lucas");…
-
8
votes1
answer460
viewsWhat is " : " (two points) in C#?
I still don’t understand what the two points represent and why this code isn’t running. int soma = 0; int[] lista = { 3, 7, -6, 10, -1, 0, -1, 4}; for (int i : lista) { if (i > 0) { soma = soma +…
-
8
votes1
answer150
viewsIs there any way to decrease the size of a function’s call?
Example: StringFormats.DateTimeToShortDateStrPtBR(); If you add this method several times in the same line the code will be very extensive, repetitive and confusing. The method is just an example,…
-
8
votes2
answers139
viewsWhat is the default (Object) for in C#?
Sometimes I come across the keyword default in the C#: object obj = default(object); string str = default(string); int number = default(int); What good is? In which scenario can I apply this?…
-
8
votes4
answers1003
viewsProblem saving a change using Entity Framework
I am trying to persist a change I make to a record but am getting this error: System.Invalidoperationexception: 'A referential Integrity Constraint Violation occurred: The Property value(s) of…
-
8
votes3
answers230
viewsWhy are methods that operate pointers insecure in . NET?
Reading a bit of the . NET source code I realized that some methods have a peculiar modifier, the unsafe. [System.Security.SecuritySafeCritical] // auto-generated…
-
8
votes4
answers814
viewsWhy can’t we return a void call in a void return waiting method?
I was doing some C# tests to find out how the return issue works void. I did the following test below and realized that tests 1 and 3 work perfectly, however 2 no. Behold: public class Program {…
-
8
votes1
answer3990
viewsDifference between Thread.Sleep and Task.Delay
I am developing a client/server communication, and using Task for asynchronous communication. Previously, I had already made another communication where I used Thread, works smoothly and consumes…
-
8
votes1
answer206
viewsHow to prevent the app from being "minimized" by Appswitch(Recentapps) Xamarin Android
I need to lock the device only for one application. I use in my project a line that determines that my app becomes a launcher. So, the home screen of the device is my application and the HomeButton…
-
8
votes1
answer107
viewsWhat does @ do in variable names?
In the response code of this question on Soen I found an unfamiliar statement line on C#. I tested this line and it works, but I didn’t understand the meaning of this character @ behind the member’s…
-
8
votes3
answers440
viewsGet the elements around a selected in the matrix
The idea is to create an integer array with the amount of user-defined rows and columns. Then an existing value in the matrix must be informed and the program must return the values immediately to…
-
8
votes1
answer93
viewsC# init equals private set?
I was reading about the new implementations on C# 9 and came across the init, init-only-setters: Starting with C# 9.0, you can create init accessors Instead of set accessors for properties and…
c#asked 3 years, 6 months ago Ricardo Pontual 21,129 -
7
votes2
answers461
viewsWriting conventions for ASP.NET controls
When you drag a control from Toolbox to a Web Form Visual Studio automatically adds an ID to this control consisting of its type with uppercase first letter and a number. This is the same pattern…
-
7
votes4
answers1385
viewsHow to replace {vars} in a string?
I have a string string str = "Bem vindo {Usuario}. Agora são: {Horas}"; I want to replace {Usuario} by a name and {Horas} by the current time, how can I do this?…
-
7
votes2
answers2862
viewsHow do I turn my computer off, restart, sleep programmatically?
I would like to add these options in a program, after finishing a task the computer would be shut down/restart/put on Sleep. How can I do that?
-
7
votes1
answer1780
viewsHow do I know if at least one element of a list is contained in another list?
I have two lists: var lista01 = new List<int> { 1, 2, 3, 4, 5 }; var lista02 = new List<int> { 7, 7, 7, 7, 7 }; I need to check if at least one element of list 1 exists on list 2, then…
-
7
votes1
answer792
viewsHow to export an HTML/C#(Razor) page that contains SVG elements to PDF?
I am currently working with Highcharts, a javascript library that generates graphics. It has an export component, but only exports the chart itself, still need to assemble the PDF layout. For the…
-
7
votes2
answers4107
viewsDictionary Search
I have the following Dictionary: public static Dictionary<string, string> ObterCodigo() { return new Dictionary<string, string> { {"18", "Teste"}, {"19", "Teste"}, {"02", "AAA"}, {"03",…
-
7
votes2
answers2415
viewsStored Procedure in Entity Framework without edmx template
I have a project that uses the Entity Framework without a model edmx, we register the entities manually create a class and insert it into the context. Someone uses this format and knows how to…
-
7
votes3
answers1774
viewsUpdate generating duplicate key error
I have a web application on . net 4.5.1 with MVC and Entity framework. Error occurs in a basic CRUD. I recover the object that will be the model sent to the view with the following code: Professor…
-
7
votes3
answers3924
viewsHow to know the week of a given month?
I am working on ASP.NET MVC 4, and I intend to know what is the week of a given month. For example, the user wants to set a frequency of occurrences, and as such says: The occurrence will happen…
-
7
votes6
answers5869
viewsHow to know the number of a week in each month
I am working on ASP MVC4, and would like to know the number of weeks in a given month to generate a list of dates. For example, the user inserts a week, and in that week of each month I will…