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
-
9
votes2
answers354
viewsHow do C#properties work?
In Java I usually create private attributes and create methods getters and setters, on account of the encapsulation. I couldn’t quite understand how this works in the C#.…
-
9
votes5
answers819
viewsIs the rest of the code inside Try executed after finding Exception?
The rest of the existing code within a try is executed after finding a exception or jumps right into the code inside the catch(Exception e) try{ x = 10; //alguns erro de try catch x = 20; } catch…
-
9
votes1
answer273
viewsHow do I know that the sum of two double’s will be greater than the limit of one double?
Is there any way to know if a sum between two values in the format double will exceed the variable limit double? Example with integer: 2147483648 + 1. In this case it exceeds the limit of an…
-
9
votes1
answer289
viewsWhy use a private?
I’m learning variables public and private. If it is I who create all the code of the program, what is the need to create a variable private? It is enough that I do not program a code that accesses…
-
9
votes1
answer3112
viewsDebug and Release mode in Visual Studio, what is it for?
In my Visual Studio I’ve noticed that there are two configurations that I can’t understand what they’re for, it’s them Debug and Release, is part of the option Solution Confugurations. Could someone…
-
9
votes1
answer262
viewsHow could I improve the code of this paging control?
I set up a pagination control for a blog I’m building, but I’m not sure I did it the right way, I tried to copy the pagination control of the Stack Exchange sites. Could you look around and tell me…
-
9
votes2
answers331
viewsHow to implement a "slim" controller
I am working on a prototype of an ASP.NET MVC application, where I want to leave my controller lean (with the least amount of code possible), for such, not making business logic in it, but rather in…
-
9
votes1
answer727
viewsHow do I change a chart caption?
I’m developing a c# application using the Windows Form chart. I would like to know how to put the values of the x-axis as the legend of it. string[] nomes = { "eduardo", "jorge", "chris", "matheus"…
c#asked 9 years, 2 months ago Matheus Barros 91 -
9
votes1
answer1327
viewsDatabinding, Dataset, Dataadapter and Datagridview: What are they for, how to use and in what order?
I’ve been trying to learn how to use Datagridview control for weeks (yes, weeks). Connecting to the bank using the designer is very easy, but I want to do it by code and I can’t. I saw some…
-
9
votes4
answers810
viewsSQL LIKE clause does not work with Sqlparameter
Following the recommendation that the @Maniero fez in that question I decided to parametrize the darlings SQL of my program. Behold: private void btnConsulta_Click(object sender, EventArgs e) { if…
-
9
votes1
answer151
viewsWhat is "global::" in C#?
I was editing a source code for an application I’m writing in C#, which uses GTK+. I have some knowledge of C#, but did not understand why some variables were written when I mounted the UI in "drag…
-
9
votes2
answers1880
viewsUnity 3D and Android, how to handle txt file?
How to do in the Unity 3D read a arquivo txt line by line and store in a vector using C#. Well, I managed to manipulate the arquivo .txt, however in Android it doesn’t work. Follow the code I used.…
-
9
votes1
answer242
viewsWhat are the differences between BCL and FCL?
The Base Class Library (BCL) Framework Class Library (FCL) are components of the .NET. This defines what each one does? What goes into each one?
-
9
votes1
answer126
viewsA property occupies space in the object?
I was reading a question about properties and saw that she is at the same time one or two methods. Do you have any additional cost in memory and processing in using it? If you don’t use the code you…
-
9
votes2
answers967
viewsHow to test private methods in C#?
How to test private methods using Microsoft.VisualStudio.Testtools.Unittesting and Moq My test class is like this: [TestClass] public class ClasseDeTeste { private MinhaClasseComMetodosPrivados…
-
9
votes2
answers1167
viewsForeach of C# vs Foreach() of EF6
Follows code: ForEach() of EF6: var result = ctx.Table.Where(x => x.User == "João").ToList(); result.ForEach(x => x.Read = true); ctx.SaveChanges(); foreach of the C#: var result =…
-
9
votes1
answer94
viewsWhy can Unboxing only be made for the type that was previously performed Boxing?
I’ve been searching for why there is Unboxing and Boxing, the answers I found say there is to value types have the same behaviour as Reference types, for example on non-generic lists ArrayList. So…
-
9
votes1
answer1028
viewsWhat is the maximum number of items I can put inside a List<T> in C#?
I have several questions of performance in my application. What is the maximum number of items I can within my List<T> and what is "acceptable" within good practice.
-
9
votes2
answers785
viewsArraylist versus List
Why in C# we should prefer to use the List instead of ArrayList?
-
9
votes3
answers189
viewsSQL - Restrict query data
Good morning, I have an app in WebForms than from two DropDownList obtain data from a database in MS SQL Server 2012. At first DropDownList it will present the name of several companies in the…
-
9
votes2
answers228
viewsIs there any functionality similar to Assert (affirmations) in C#?
In languages like Python there is an assertion mechanism (assert) which aims to state whether an expression is true and, if there are failures, throws an exception. In most cases, I think it’s best…
-
9
votes1
answer1372
viewsPass two templates to a sign-up view
I have a login registration screen. I have to fill it with values registered in the database. Follows the codes: Models: public partial class Aba {…
-
9
votes1
answer832
viewsHow to copy a file from the network to my computer using C#?
I have a desktop application that needs to copy media files from a server, videos and images. The server is on the same network as the terminal on which the program will be installed. The problem…
-
9
votes2
answers955
viewsHow to manage approval and production environments with Team Services?
I’m on an ASP.Net C# project that’s starting now, but I come from ASP Clássico, where things are very different. In this new project we need to create and manage approval and production…
-
9
votes4
answers785
viewsShould I use a "Try-catch" to identify if a password is wrong?
On the screen of login, carry out the verification in the bank by means of a select, and I’m using the catch to capture this exception. It is correct to use the catch for that guy? if (Usuario !=…
-
9
votes1
answer1043
viewsHow to resolve error: "XXXX app stopped"?
Good afternoon, I have an application in language C# which develops an app for android (using Xamarin). The application works normally for android of versions 2, 3, 4 and 5. However, using a device…
-
9
votes2
answers1951
viewsApp - Xamarin or Ionic?
I need to create an App and would like to know which of your technologies is the most suitable for mobile development. What is the main difference between Xamarin and Ionic? Which of the…
-
9
votes2
answers477
viewsWhat types of resources are released in a "using" statement?
According to Microsoft documentation: The using statement provides a convenient syntax that ensures use correct of Idisposable objects. Source. That is, the interface Idisposable provides a…
-
9
votes0
answers152
viewsError: Valuefactory tried to access the Value property of this instance
Every time I create any project Xamarin in the Visual Studio 2017 the following error is displayed when running the application: Erro: ValueFactory tentou acessar a propriedade Value dessa…
-
9
votes2
answers228
viewsIs Tuple the same as creating an object?
I’ve used the Tuple a few times and today came the doubt, that: public class User{ public String Name {get; set;} public String LastName {get; set;} } new User(){ Name = "Leonardo", LastName =…
-
9
votes2
answers674
viewsDo I need to use Visual Studio to program in C#?
I want to learn C# to become one of my main languages, but my current PC is kind of outdated and ends up not running Visual Studio well, but with Visual Studio Code it’s okay, I need Visual Studio…
-
9
votes1
answer767
viewsMulti-client Web API Structure
I’m in the following situation: I have a web application that accesses the data through a C#Webapi. I need to apply the concept of multitenancy in order to allow my application to be accessed by…
-
9
votes2
answers2912
viewsWhat is the purpose of the Gethashcode() method?
I’m using Resharper to automate the method override Equals and the operator ==. One of the methods the tool has overwritten is GetHashCode: public override int GetHashCode() { unchecked { return…
-
9
votes2
answers4792
viewsWhat is Yenumerable and Yenumerator for?
I made a combo of questions about IEnumerable and IEnumerator not only to help me but to help everyone who needs a more didactic explanation. Question 1 Could someone explain in a more didactic way…
-
9
votes2
answers93
viewsMethod equivalent to Biginteger.and() in C#
I need to convert the java code below to C#: public static boolean verificaPermissao(BigInteger perm1, BigInteger perm) { if (perm1 == null || perm == null || (perm1.equals(BigInteger.ZERO) ||…
-
9
votes3
answers1480
viewsHow to make a query through LINQ ignoring accents?
I wonder if it is possible to make a query with LINQ to compare two strings and ignore their accents. That without my Collation in the database is set as AI (Accent Insensitive) and I don’t need to…
-
9
votes1
answer98
viewsWhat are the benefits of using the => operator in common methods that are unrelated to Lists or Lambda Expression?
I asked the following question: What value is checked in a condition operation with a variable value assignment? and the user @Maniero answered me, however, in the reply he used an operator and that…
-
9
votes2
answers1682
viewsGet data from each row of a column in C#
Here’s the thing, I got a DataGridView with several columns. In each row of this DataGridView a program installation path will be shown. With this value displayed, I would like to use it to get the…
-
9
votes1
answer292
viewsIs it possible to determine whether an array of bytes represents a pdf file that cannot be edited?
Context I have two steps in my service, uploading and downloading the file. When uploading to the service I receive the data through an array of ASCII bytes. This data is stored in a database. In…
-
9
votes2
answers993
viewsIs there the equivalent of Andalso and Orelse in C#?
In VB.NET there are two interesting operators: the AndAlso and the OrElse. When used, the logical expression is not evaluated in full immediately. See the following example: If (Not Usuario Is…
-
9
votes4
answers1255
viewsConverting Httppostedfilebase to byte[] : Exception_wasthrown
Follows code: Controller (with post action): var file = Request.Files[0]; var bytes = ConvertTo.Bytes(file); Convertto class : public static byte[] Bytes(HttpPostedFileBase result) { var length =…
-
9
votes2
answers995
viewsLazy Loading EF Core, upload daughter entities and daughters?
I have a Web Api I’m developing using the DotNet Core and EF Cor but is with the Lazy Loading active, only that in some cases I need to load the entities daughters and daughters of daughters, I…
-
9
votes2
answers1801
viewsAsync/Await with threads (C# 7.2)
I have this code and as you can see I created two examples, Parallel and Notparallel. I expected both to return me 3000ms, because both should run async (2000 and 3000) and the total time would be…
-
9
votes1
answer1024
viewsGenerate classes with XSD or import WSDL [ANS / TISS]
To ANS provides the files .XSD, and the .WSDL for the implementation of the protocol TISS. Sand I type the code by . XSD, I have the classes structured correctly. Example: namespace TissV3 { class…
-
9
votes5
answers1894
viewsTest for string fill
When reading a post on good programming practices, more related to validating the filling of strings, I came across the following: Very slow check: string ret = String.Empty; if…
-
9
votes2
answers1119
viewsWhere is Session stored in ASP.NET Core and how best to use it?
Knowing that ASP.NET MVC when it comes to Session should be taken care not to abuse too much of such functionality due to its memory consumption by the server can "weigh" the application. Reading a…
-
9
votes3
answers170
viewsHow to change property access level in an inheritance?
I have a class that when inherited I want one of its public attributes to become private, so that the user does not have access to the use of this variable in this class, but I do not know how to do…
-
8
votes3
answers424
viewsServer.Mappath fails within Global.asax
In the code below, when I try to call the Mappath function inside Global.asax, an error occurs at runtime with the following error message: System.Web.Httpexception (0 80004005): Request is not…
-
8
votes2
answers2353
viewsHow to get the integer value of one of the constants of an Enum?
I have an Enum (enumeration) calling Notas and need to obtain the integer corresponding to one of its constants. public enum Nota { Otimo = 5, MuitoBom = 4, Bom = 3, Regular = 2, Ruim = 1,…
-
8
votes2
answers457
viewsHow do I log in through my Microsoft Live app?
I would like to know how I can log in through my application, whether Web or Desktop, on Live? I’ve looked for some things, but I haven’t succeeded. UPDATING So, as the bfavaretto suggested, I…