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
-
10
votes2
answers73740
viewsHow to access the print screen image?
When we hit the button Print Screen from our keyboard, the screen image is saved in some cache, in memory, somewhere, because when we give Ctrl V after, in Paint for example it trims, how to access…
-
10
votes2
answers7394
viewsEntity Framework update and delete associative entity
I have a student table that has many to many relationship with the course table. Thus resulting in the table CursoAluno. I would like to know the correct way to the update and the delete table…
-
10
votes1
answer1708
viewsASP.NET Identity and Claims
Still on ASP.NET Identity, following another question I asked about this (Example of ASP.NET Identity using SQL Server), an interesting topic within the same subject would be regarding Claims. What…
-
10
votes1
answer2783
viewsHow to create a login and password page in ASP.NET?
I’m trying to create a login control for my application but I’m not finding a way to do that. I would like it to be a complete login control, where I can register new users, recover their passwords,…
-
10
votes2
answers5236
viewsRelationship N for N and One for N with Codefirst Data Annotations
How can I Relationship N to N and One to N using Data Annotations? For example: A sales drive has a user, and a user can have multiple drives. This same sales movement has several products, and each…
-
10
votes1
answer9035
viewsScroll bar on a table with bootstrap
I have a table, where I upload database information into it. It has two columns (CNPJ and Social Reason). The table I mounted with bootstrap. I would like her to have a maximum height and create a…
-
10
votes1
answer358
viewsWhat are closures and what is their use?
The answer to this question on lambda What are lambda Expressions? And what’s the point of using them? talks about closures and Tree Xpressions, however, does not have a clear example of what they…
-
10
votes1
answer2456
viewsReturn Object Code as soon as inserted
I need to do an Insert in the Entity Framework and at the same time returns the code of the inserted object, thus preventing new access to the bank.
-
10
votes2
answers19497
viewsHow to get a snippet of a string?
I have a string like this: ~/Areas/Teste/Views/home/index.cshtml I just need the word that comes right after ~/Areas/, in the case Teste (remembering that this word may vary in size). How do?…
-
10
votes2
answers440
viewsExport Reportviewer report to CSV
In the Reportviewer using Winforms, when creating the report I only have the option to export to PDF, Excel and Word and need to add the option to export in CSV.
-
10
votes3
answers667
viewsWhat are these attributes in the properties?
What are the names of these "attributes" and what are they used for? Examples: in the declaration of a class: [ComVisibleAttribute(true)] public sealed class SerializableAttribute : Attribute in the…
-
10
votes3
answers1631
viewsConcurrency control in database insertion
I have a competition control problem in entering data from a table. The scenario is as follows:: There is a table that records daily data according to user requests, and this data cannot be…
-
10
votes3
answers11142
viewsDifference between Console.Read(); and Console.Readline();
I’m starting to learn C# and I got a little confused by one thing. What’s the real difference between Console.Read(); and Console.ReadLine(); ?
-
10
votes1
answer4542
views3 layers vs MVC
3 layers: DAL (Where the classes (model) and bank operations are located BLL (Where the business rule is) Presentation (Usually the WEB) An example: DAL public class AlunoBanco { public void…
-
10
votes2
answers16045
viewsForeach or lambda in lists
Which one do I get the best performance to get the value of a given in a list? I do foreach or lambda(when possible, of course)? I can have this: foreach(var i in lista) { var teste = i.NmCampo; }…
-
10
votes3
answers1471
viewsUse Command Line with C#
In my work I use the command line, and wanted to improve the work in my company. To do this, I thought of creating a program in C# for people who do not know how to work with command line. I thought…
-
10
votes2
answers1467
viewsMethod to execute when destroying class instance
There is some way to execute a method automatically by destroying a class instance. I have a generic SQL class, where in the constructor I call a method that opens the connection. Only I want to…
-
10
votes4
answers844
viewsHow to create properties dynamically in C#?
In Javascript it is easy to create an object with new properties. var obj = { "propriedade1" : "valor", "propriedade2" : "valor" } It is possible to do something similar in C#? var lista = new…
-
10
votes4
answers25170
viewsFormat a CPF string?
I have a problem, in an app the user type the CPF, but only the numbers because it is very complicated to create mask on Windows Phone, and this CPF will be 'drawn' in a picture of a card, and to…
-
10
votes3
answers129
viewsHow to create mandatory exceptions in C#?
Is there any way to make a method make an exception that must be dealt with when the method is invoked? I used the throw new Exception("mensagem de erro") but the treatment is still optional when…
-
10
votes3
answers6925
viewsHow to send 2 Controller objects to the View in C#?
I made a query in the database in 2 tables and saved in 2 objects in the controller, but I can only send 1 object to the view. // Controller // Pego os dados do BD e salvo no objeto var objPessoa =…
-
10
votes4
answers621
viewsCreate Windows Service Auto-Updatable
I would like to know the recommended procedure for a Windows service to auto-update. The main questions are: After the service download a new version of itself, how to stop the service and restart…
c#asked 9 years, 3 months ago rubStackOverflow 7,372 -
10
votes1
answer3515
viewsWhat is Partial View?
Using the Controller I can return a Partial View, JSON, string and other things. What is a Partial View? Is it widely used in projects? Why use it?
-
10
votes2
answers455
viewsString Interpolation performs better than string. Format?
I use Resharper and a few days ago I started using some C# 6 features. In various parts of the code use string.Format() and I realized that Resharper suggests that these snippets be replaced by…
c# .net string string-concatenation string-interpolationasked 9 years, 3 months ago Jéf Bueno 67,331 -
10
votes3
answers1283
viewsRemove Saturdays and Sundays from Calculation
I have a project where I work with activities of a project, my activities have a certain time to be completed, but the project has to make the calculation only with administrative days. For example…
-
10
votes3
answers16306
viewsValidate Credit Card Number
How do I validate credit card numbers? I will not integrate with card operator, I just need to validate the number, as with the validation with CPF.
-
10
votes1
answer3523
viewsConvert int or string to Enum
How to convert type variables int and string for a enum?
-
10
votes2
answers525
viewsWhen is it recommended that a class implement Idisposable?
I use the IOC standard in my project which facilitates the call of procedure type Resolver.Resolve<IPedido>().GerarPedido(), however, I did not want to leave "loose" in this way, I would like…
-
10
votes1
answer398
viewsDoubt about mapping in Entity Framework 6. "readonly" properties
I have three tables in my bank: TB_COLABORADOR TB_JORNADA TB_JORNADA_COLABORADOR To TB_JORNADA_COLABORADOR makes the association of employees with the journey and vice versa through the fields…
-
10
votes1
answer3855
viewsReceiving data via serial connection C#
I need to do a program that has to send a command to a radio connected via serial port and this returns your ID. The connection to the port and the sending of data is ok, when I send something the…
-
10
votes3
answers821
viewsWhat is the difference between "decimal. Divide" and the traditional "/" in C#?
decimal a = 10/5; Returns 2 decimal b = decimal.Divide(10,5); Returns 2
-
10
votes1
answer658
viewsWhat tools are available for C#project installers?
I’m having trouble finding a satisfactory installer solution for my Windows Forms and WPF applications. What Microsoft makes available is flexible or I’m not finding? What do you use? What do you…
-
10
votes2
answers153
viewsIs there any way to run C# from the command line in interactive mode?
I’m used to using PHP and Python, languages that allow you to run on the command line in interactive mode, so it’s easier to test or learn something new, since I won’t need to compile all the time…
-
10
votes2
answers375
views -
10
votes2
answers4980
viewsHow to determine the last element of a list in a foreach?
Given any list, how to know if the foreach is in the last element? There are some ways to do this, the one I see most is to save the last element and check if the current element is the same, but…
-
10
votes2
answers433
viewsKeep data between sessions
I have an ASP.Netet MVC project where I file a report that requires quite resource of the machine in question of processing. I have a Action that generates and another that returns the report data…
-
10
votes2
answers229
viewsCan try catch be replaced by using?
I always used the blocks try, catch and finally when programming in Java, and when I switched to C# I noticed that some codes exchange the try/catch for using. Example: using (FileStream fs = new…
-
10
votes2
answers5514
viewsIs there a correct way to comment on a code snippet?
Is there a correct way to comment on a code snippet? For example: // Esconde a tela this.Hide() or would be: this.Hide() // Esconde a tela or even: this.Hide() // Esconde a tela Is there some kind…
-
10
votes1
answer3650
viewsWhat is the difference between virtual and Abstract methods?
In which cases should I prefer to use one type instead of the other?
-
10
votes2
answers342
viewsRedirect from Http to Https on Owin + Oauth + Google Externallogin
Host where my application is hosted uses ARR to redirect all pages to Https. The problem is that the way the code of the asp.net mvc understands that the requisition is http, even though https. When…
-
10
votes3
answers1653
viewsPicking up part of the phone
In the registration, the user registers his phone and this field is masked (99)99999-9999 and this is saved in the BD. if I want to use only the DDD of this, and the separate numbers, how should I…
-
10
votes1
answer1055
viewsIIS mount server on PC at home
Hello, I need to know if I have how to set up, etc, the IIS in a notebook, so that when this notebook is connected in the company, it works as my server, so that I can access my ASP.NET MVC…
-
10
votes1
answer3282
viewsHow to compile the database to install together with a C#application?
I’m developing an application in c#, and I need to know if I can compile the database to install together with the application, I’ve seen something here talking about Sqlite, but I don’t know the…
-
10
votes2
answers424
viewsWhat is the purpose of empty command blocks or which do not belong to any command?
A command block is composed of two or more commands between keys {...//Comandos}, I can use them for the following situations I already know: In a if: if(codicao){...//Comandos}. In a for:…
-
10
votes1
answer5341
viewsOrder By with List<>
It is possible to make a OrderBy in a List<> setting the value for comparison? Example: mRel.OrderBy(s => s.Status == EnumModel.StatusGeral.Novo).ToList() My Code:…
-
10
votes2
answers424
viewsDeserialize Json in which the key is a number
I’m trying to deserialize Json with C#, but I found a problem. In Json you can use numbers in the names of "keys" (keys), but we can’t use numbers in property names in C# Example: Json: "c":[ {…
-
10
votes2
answers932
viewsBest practices when working with Multithread
Is the pseudo-code below following the good practices for an asynchronous code? It should: Synchronously start several tasks; After starting tasks, wait for all tasks to complete a post-processing;…
-
10
votes2
answers551
viewsWhat is the point of an explicit C#interface implementation?
I usually use interfaces in PHP and I was able to do a similar example, only for tests, in C#. class MyClass : IWriter { public string Writer(string str) { return str; } } interface IWriter{ public…
-
10
votes2
answers1070
viewsPath from previous folder
How can I get the path from the previous folder? For example I have this path : C:/Pasta1/Pasta2 And I wanted to get in the way of folder 1 C:/Pasta1 How can I do that?…
-
10
votes1
answer1490
viewsPolymorphism or inheritance?
I’m learning about polymorphism and I’ve been wondering if what I’m doing is actually polymorphism or just inheritance? If it’s polymorphism what’s in my code that I can clearly identify is…
c# oop software-engineering inheritance polymorphismasked 8 years, 4 months ago Mauricio Ferraz 2,074