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
-
16
votes3
answers3624
viewsWhen to use asynchronous or synchronous method?
When to use asynchronous or synchronous methods in controllers (index, search, delete, create) of ASP.NET MVC applications? Can I lose performance? In which situations should I use one or the other,…
c# asp.net-mvc .net entity-framework asynchronousasked 7 years, 6 months ago George Wurthmann 4,415 -
16
votes3
answers8395
viewsDeserialize JSON Array in an Object Array
Good afternoon, I decided to ask because I’ve been holding on to this for three days and as much as I’ve looked, I haven’t found a solution to my problem. Access a Web Service via C#, Httpclient,…
-
16
votes3
answers675
viewsWhy can’t I declare an attribute using the var keyword?
The keyword var allows me to declare typed variables, and allows variables to be defined implicitly. Example: var i = 10; The compiler will assume that my variable i is of the whole type int.…
-
16
votes3
answers4507
viewsWhat is the point of "interrogation" in the type statement in C#?
I saw this code written in C# on the Internet: namespace Test { [MicroEntitySetup(TableName = "Users")] public class User : MicroEntity<User> { [Key] public int id { get; set; } public string…
-
15
votes1
answer1873
viewsMobile App Multiplatform with Xamarin
Setting This question is more about architecture. I recently started learning Xamarin to develop Mobile Apps, Xamarin, which until then has been very flexible, has bindings for native Android and…
-
15
votes4
answers1141
viewsHow to simulate "tail recursion" in C#?
No. Net, I know it is possible to make cause calls because the compiler of F#, when optimizing code, transforms a function with tail recursion into a function with a loop, thus avoiding stack…
-
15
votes2
answers2432
viewsHow to create a Date list with a specific day
I am working on ASP with MVC 4, and I hold create a list of dates from the data entered by the user. For example, the user inserts the day of the month in which a certain occurrence will be made. It…
-
15
votes3
answers15338
viewsHow to validate CPF with Dataannotation on Client and Server?
I need to validate CPF with Data Annotation, and check for duplicity.
-
15
votes5
answers17754
viewsHow to solve accent problems with ASP.NET MVC?
I’m having problems with accentuation in ASP.NET MVC 5. I am using Visual Studio 2013 Professional and in the application . Net 4.5. SQL Server 2008 and Entity Framework 6. The browser is Google…
c# asp.net-mvc asp.net-mvc-5 entity-framework visual-studio-2013asked 10 years, 8 months ago user3628 -
15
votes2
answers17329
viewsWhat does "!" (exclamation) mean before a code snippet?
There are many basic things I do not know, for example how to read exactly this exclamation the way it is placed in the following section: if…
-
15
votes1
answer167
viewsWhat is the character function ? in the variable type in C#?
I see many third-party codes and I often see the use of the question mark on the type of the variable. Example: public bool? Status Could someone explain to me the difference between not having this…
-
15
votes3
answers5859
viewsDevelop for multiple platforms using C# and Xamarin Studio
To not have to learn various technologies to develop for the various mobile platforms, wanted to use only C#. However I have some doubts, namely: Xamarin Studio is free? With the same code, the…
-
15
votes4
answers957
viewsMultiple Contexts Migrations Entity Framework
I have several projects and each project has a context. I would like to know, how to use the Migrations to update and generate only one database of these various contexts?
-
15
votes2
answers5787
viewsCut string when it reaches space
Example: I have a string "João da Maquipe", as I do to cut in space, leaving as a result: "João" or "João". whatever. In PHP I know, but in C# I have no idea.
-
15
votes2
answers310
viewsGo with a ";" at the beginning of the loop, which means
I picked up a code with a code like this: for (; indField > 0 && indMask > 0; ) What does that mean ";" at the beginning and end of the command?…
-
15
votes2
answers5495
viewsWhat are Async methods?
I noticed that most methods in C# have an equal method but with a name async. What are these methods and how they work?
-
15
votes2
answers883
viewsWhat is the difference, in practice, between Session and Application?
I’m studying about Tecnologias Web, and during my class there was a topic about concepts involving Session and Application. The technology addressed during the class was C#. I didn’t quite…
-
15
votes4
answers6318
viewsHow to display combobox-related value in the textbox?
I am doing a project in C# and SQL Server, and I need the item selected in the combo to display the corresponding values in a textbox. Follow the codes I’ve tried: private void…
-
15
votes2
answers1617
viewsWhat is LINQ technology?
Today reading some contest questions, appeared one in which it was LINQ technology. Without delving too much into the research I noticed a number of quotes as: LINQ to SQL LINQ to XML (C#) LINQ to…
-
15
votes1
answer1419
viewsWhat is the advantage of semicolons in programming languages?
I know that in programming languages like Java and C#, the semicolon indicates the end of the instruction, as in the example below, in C#: System.Console.WriteLine("Hello, World!"); However, there…
-
15
votes2
answers2209
viewsWhat is typing style?
On Wikipedia, on the page about C# says about the "typing style" of the language: static and dynamic, strong, safe and insecure, nominative, partially inferent What is typing style? What do the…
-
15
votes1
answer193
viewsWhat is the minimum size of an object in memory?
I received an answer in my question that talks about a overhead that the object has. Every object has this overhead? An object without data also has this overhead? Exists object of size 0?…
-
15
votes3
answers361
viewsIs it correct to call a method, and pass your null parameters?
For example, I have the event of click of a button calling the method below: //Evento this.serviçoToolStripMenuItem1.Click += new System.EventHandler(this.Nivel_Serv_Click); //Metodo private void…
-
15
votes3
answers2510
viewsWhen not to return Task in async methods?
Normally, in some time-consuming tasks, I use asynchronous methods: public async Task myLongRunningOperation(int i) { ... } However, in what situations I don’t necessarily need to return a Task?…
-
15
votes2
answers1287
viewsWhat is the purpose of a static constructor?
I’ve always used builders as follows: public MinhaClasse() { //Algo ... } However I found that in C# it is possible to create a static constructor as follows: public class MinhaClasse { public…
-
15
votes1
answer201
viewsDoes creating many static classes impact system performance?
I’ve been creating many static classes to facilitate and clear code, such as a Google Translate API call. public static class GoogleTranslate { public static string Translate(string word){ //código…
-
15
votes3
answers243
viewsDoes C# have native serialization?
In PHP there is a language proper data serialization feature. I mean: I’m not talking about using JSON or XML, but I speak of a serialization in a format that is proper to the language. For example,…
-
15
votes8
answers2223
viewsError: not all code paths Return a value
I would like to understand why my code is causing the error not all code paths Return a value using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using…
-
14
votes3
answers30199
viewsHow do I round numbers to the nearest integer?
I have numbers double as double a = 0.4, b = 0.5; How do I round it up?
-
14
votes4
answers2252
viewsWhat is the advantage of hiding the class constructor in favor of a static method (no .NET)?
My leader uses this pattern in ALL his classes (I’ll give the examples in C#, but it goes for any . NET language): public class MeuTipo { private MeuTipo() { } // esconder o construtor public static…
-
14
votes3
answers12403
viewsGet MAC Address from application client machine
I would like to know the best way to get the MAC Address from the client of my Asp.Net Web Forms application. As it is a low level information, I believe it is not as simple as it seems.
-
14
votes6
answers14419
viewsWhich database should I use in a small desktop application?
I read a bit about the Meta and I thought that this question does not escape much from the current rules of the site. Risking losing reputation, come on: At the moment I work in a small company that…
-
14
votes3
answers337
viewsDoubt about the responsibility of a get()
It is acceptable to have a method getter that you receive a parameter to be able to have a return variation? Example: getAllNome("M"); <- retorna tudo que for masculino. getAllNome("F"); <-…
-
14
votes3
answers27590
viewsHow to encrypt and decrypt MD5 data using C#?
How to do MD5 encryption with C# of a text or file? And once it’s encrypted, how to decrypt?
-
14
votes3
answers21251
viewsWhat is a virtual class, attributes and methods?
What is a class, attribute and virtual method? public virtual class nomeclasse { public virtual int id { get;set; } public virtual void metodo() { } } What difference? When to use?…
-
14
votes2
answers3795
views -
14
votes4
answers9242
viewsDatetime field error message
I have a field in my application in mvc Asp.net c# to put start date and end date. [Required(ErrorMessage = "A data de início é obrigatória")] [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}",…
-
14
votes3
answers13485
viewsChange the Datetime Timezone.
I am hosting my system on a server that is in the USA. So when using the DateTime.Now returns the date and time of the US. I would like you to return the date and time of Brazil. It is possible?…
-
14
votes3
answers1073
viewsIs controller returning HTML to View wrong?
I used this solution because when trying to render a Table in a view with many records the user’s browser gave Crash, I know it is a solution not much elegant but it was the only solution that came…
-
14
votes1
answer41651
viewsFormat value with Brazilian currency mask
I have a stored trial that returns a credit amount for a certain consortium quota. The return of that value would be like this: 167900. But it should be so: R$ 167.900,00. This value I feed a…
-
14
votes2
answers352
viewsWhat does the operator = mean in C#?
I have a function in C#, where I decrypt a string and need to convert into a function in SQL Server for technicians to be able to work with the decrypted value. There is a foreach, I don’t…
-
14
votes2
answers511
viewsWhat are nesting guys for?
I know that C# supports nested types, that is, it is possible for me to declare one class within another. For example: public class A { // Propriedades e métodos da classe A public class B { //…
-
14
votes2
answers288
views -
14
votes2
answers11938
viewsGet national holidays
I am making an application and would like to know if there is any way to get the national holidays. For example: Some Google Calendar API where I can get some XML to consume..
-
14
votes2
answers306
views#Region is an antipattern or a Smell code?
The #region from Visual Studio he hides the codes, everyone says he’s bad, because he exists? It’s a antipattern or a code Smell?
-
14
votes1
answer11725
viewsCLSID component COM class factory recovery failure
I have developed an application on my pc that does the following: from an upload of a word document, it generates a new document with some basic information. To generate this information, it opens…
-
14
votes3
answers261
viewsWhat is the advantage of using the Set<> method?
What is the advantage or difference in using the method Set<> and I can do the same thing without him as in Alternative 2? Alternative 1 var aluno = contexto.Alunos.First(x => x.Id ==…
-
14
votes2
answers5656
viewsWhen and where to use a delegate in C#?
I’m new to C# and I still don’t fully understand the concept of using a delegate: public delegate void HTTPRequestsHandler(string url); I would like to know when to use them and in which cases a…
-
14
votes2
answers289
viewsNew C# 6 functionality "Auto-Property initializers" is just a facilitator?
One of the new C#6 features is the possibility to initialize properties at the time of declaration. public class Customer { public string First { get; set; } = "Jane"; public string Last { get; set;…
-
14
votes6
answers2762
viewsHow to walk an Enum?
Here’s what I need to do: string and go through it and pick up each letter found and add with its corresponding value, type: a = 1, s = 19 and etc. Well, I made a enum with all the values of string,…