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
votes1
answer173
viewsAddorupdate - use array as parameter
I’m doing tests with Entity Framework and I had a problem when placing a array as a parameter. Why when I assign the conversion of array in a function variable and directly in the method parameter…
-
8
votes3
answers779
viewsPassage of parameter C#
I have the following code in js function consultaSolicitacao() { id = getVar("id"); serviceURL = "/Solicitacao/ConsultaSolicitacao"; $.get(serviceURL, null, function (data) { var aux = data.length;…
-
8
votes2
answers576
viewsNotice: "Possible Multiple enumeration of Ienumerable"
I was doing some operations where I use collections. In one of these I needed to take a break (range) of numbers and I did the following: var range = Enumerable.Range(0, 4); And then I tried to do…
-
8
votes2
answers500
viewsHow to use Regular Expression correctly
I’m studying about the RegularExpression, But I don’t quite understand. In my Model the property CPF must be filled in by numbers only: [RegularExpression(@"[0-9]", ErrorMessage = "CPF deve conter…
-
8
votes3
answers466
viewsBest practice to check if the module is being used
My question which perhaps - I hope not - can be considered as of opinion, is conceptual and even simple. In most applications, we work with features that when used by multiple users at the same time…
-
8
votes1
answer355
viewsCentralize (use only one) a Try-catch for every WPF application
Is there any way to centralize a try-catch for every application in a WPF application with C#? I created a window to use as MessageBox customized. When there is an error in any system registration…
-
8
votes1
answer112
viewsCan you use a dialog to open both folders and files?
Well, I’m using the openfiledialog to open files, however the software needs to receive files or folders, because it compressed and zipped (.zip) and then make a symmetrical cipher. I have searched…
-
8
votes1
answer399
viewsHow to export a Datatable to Excel without formatting the information?
I need to export a number to Excel, but it always formats in an inappropriate way. Expected form: -8,0902322222234 Received: -809.023.222.222.234 The data from the Datatable are typed with string.…
-
8
votes1
answer452
viewsWhat is a type class "class Minhaclasseexample<T> Where T: new(){}"?
A class class ExemploClass<T> is a list? See the example class below: public abstract class MinhaClasseExemplo<T> where T: new() { public T value {get; set;} } Which means every part of…
-
8
votes1
answer1061
viewsCapture the sound of a microphone in Windows via C#
How do I capture the audio the microphone receives in Windows with C#? I want to develop a software that receives the outside sound and based on that it changes the volume of my computer.
-
8
votes3
answers117
viewsArchitectural problem where access to construction methods should be controlled
I have a class for tree that will have the addition of trunks, branches, leaves and fruits. I need the class to give access to certain methods only after others and that the previous ones cannot be…
-
8
votes2
answers1716
viewsWhat is the difference between Idisposable implementations?
I confess that I still don’t understand everything about how to manipulate the destruction of an object in the C# and now, as I’m testing Visual Studio 2015 Preview, when implementing a database…
-
8
votes2
answers881
viewsHow to avoid code repetition between classes?
To report on my application I have created several classes, and each class is responsible for a report, however, there is a repetition of a lot of code by those classes that I would like to avoid,…
-
8
votes2
answers1730
viewsTime-out expiring faster than expected - ASP.NET
I am with an application that is working ok, however, when I spend a little time without interacting with the page the user authentication drops and the system returns to the login screen. i am…
-
8
votes2
answers268
viewsShoot event only once
I’m doing an interface in Visual Studio 2015, how do I hold an event just once? For example: private void textBox5_Click(object sender, EventArgs e) { textBox5.ForeColor = Color.Black;…
-
8
votes2
answers653
viewsName collision between class and namespace
It’s wrong, bad practice or I might have problems with class like namespace? Example: namespace Cielo { public class Cielo { ... } } It’s been working, in some places it gets a little strange to…
-
8
votes2
answers7119
viewsHow popular a Dropdownlist from another Dropdownlist
I need to know how to popular a Dropdownlist from another Dropdownlist. Example: I have a Dropdownlist called Project that takes information from my DB. When I select for example "Project 1" I need…
-
8
votes2
answers321
viewsAre static classes shared by threads?
Static classes, methods and properties are shared between threads of the application? That is, if I modify the static property foo in ThreadA, and then modify the same static property foo in…
-
8
votes1
answer3777
viewsWhen should I use Modelstate.Isvalid?
When should I use the ModelState.isValid? Is it only in the insertion of data? And in the case of update and delete? We need?
-
8
votes5
answers19908
views.NET C# IIS Request cancelled: Failed to create secure channel for SSL/TLS
Gentlemen, I am trying to communicate with the recipe/SEFAZ server using an A1 certificate through an MVC5 C# application on an IIS 8 server, in the pool with my user identity. The certificate is…
-
8
votes2
answers577
viewsWhat is the purpose of unsafe command?
I saw the use of the command unsafe, in this code in the declaration of this method: public unsafe static int GetSquareStack(int value) {...} Within the method there seems to be pointer manipulation…
-
8
votes3
answers3818
viewsUpdate an item from a generic list to a specific item
How do I update a specific element of a generic list by locating by ID and passing an updated object in its place, updating the name and email? class Program { static void Main(string[] args) {…
-
8
votes2
answers1697
viewsControl view component visibility in the ASP.NET MVC 5 controller
I am refactoring a project in ASP.NET MVC 5, implementing some good practices and researching, it was mentioned that the use of if na view(Razor) is not the best practice, only that I use it to show…
-
8
votes0
answers101
viewsContent ID and Usage Policies with Youtube API
I’m trying to upload my videos on Youtube, with Usage Policy and Content Id Matching enabled. My project is on. NET with the Youtube API v3 library, but the library only allows the implementation…
-
8
votes1
answer1373
viewsHow to handle duplicate key error?
How do I handle duplicate key error? I need to display message to the user that the "Item is already registered" Something like that: try{ //tenta inserir no Banco de Dados…
-
8
votes1
answer89
viewsHow do I extract values from an Expression?
Hello. It is possible to extract from an Expression which filters, arrays, etc were used in a query? Example: public class Program { class Produto { public int Id; public string Nome; public…
-
8
votes4
answers542
viewsWhy use block using in ASP.NET MVC?
The block using {} works in the same way in both web applications and desktops in the sense of when we use it in controller? It is a good practice to declare it in the actions that there is contact…
-
8
votes2
answers1098
viewsAngular POST with custom header and CORS
I need to perform a POST request using angular (http.post) and I need to pass to my API (.NET) in my header the access credentials (I’m using basic Authentication). Authorization:Basic…
c# angularjs asp.net-web-api http-headers cross-domainasked 8 years, 11 months ago Pedro Camara Junior 6,637 -
8
votes1
answer1947
viewsHow to drag form without border?
I’m trying to implement a way to drag my form no edge while clicking and holding down the left mouse button on it, however I did not succeed. Below follows the example of my attempt at…
-
8
votes2
answers213
viewsDo I need to assign null to a variable after use?
There is a need to allocate null in the object after its use? In the example below just after using the list I have a method that takes a lot of time to run. I need to assign null to the list to…
-
8
votes2
answers708
viewsCode First and Calculated Fields
I have a class Pedido, which has a calculated field, which is the order value, composed of the sum of the items minus the discount. public class Pedido { public ICollection<PedidoItem> Itens {…
-
8
votes1
answer240
viewsDownload server memory image
I have an Asp.Net MVC project where I have an image in memory and would like to download it. See an excerpt from the code: Image imagem = default(Image); using (Bitmap b = new Bitmap(bitmapWidth,…
-
8
votes5
answers1583
viewsHow to read data from the Mysql database of an application in c#?
I have a table with 2 columns in phpmyadmin,I can connect and read one column but not the other, from the following error An unhandled Exception of type 'Mysql.Data.Mysqlclient.Mysqlexception'…
-
8
votes2
answers3639
viewsValidation of digital signature
I am developing a software integration with the legal note webservice for issuance of electronic tax notes of the city of Porto Alegre. After some difficulties I was able to fine tune the xml so…
-
8
votes2
answers107
viewsWhy are some string methods static?
I am learning C# after already working with other languages, I noticed that some methods need to be called by the class string.Concat("123","456") I usually use in other languages this way…
-
8
votes1
answer157
viewsHow to use Fluentvalidation ruleset functionality in Web API?
I would like to use a feature of Fluentvalidation calling for ruleset in a web API project, because I don’t want to have to be doing model validation manually every time a action method is called.…
-
8
votes3
answers722
viewsInitialize private fields in the declaration or constructor?
I’m modeling a class that has a private list and an internal dependency on another object: public class Teste { private IList<string> Textos; private Teste2 Teste2; } I can initiate them in…
-
8
votes1
answer125
viewsWhat is the best way to get out of a C#app?
The most common way is to go out with a return in the Main(). But I saw that there is Environment.Exit() and the Application.Exit(). When should we use each?…
-
8
votes2
answers300
viewsWhy does . NET’s Garbage ollector have several generations?
I understand why there is a Garbage Collector, but I wanted to know the advantages of making it have several generations. It seems something much more complicated, it needs to be very advantageous.…
-
8
votes1
answer156
viewsTo create a function equal to C# Array.Copy in C++
I would like to create a function similar to Array.Copy from C# to C++. This function has the prototype thus: public static void Copy( Array sourceArray, int sourceIndex, Array destinationArray, int…
-
8
votes2
answers590
viewsWhat is the useshellexecute property for?
Developing an application in c# I came across the property UseShellExecute in the following code snippet: ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = false;…
-
8
votes1
answer122
views -
8
votes1
answer127
viewsStatic members are collected by GC when no longer needed?
In a class that has a static variable, it exists throughout the application. The linked object is collected at some point? Example: public class Exemplo { private static List<int> lista = new…
-
8
votes3
answers157
viewsHow does field initialization work in constructors?
In the C# documentation it is written: If a class does not have a constructor, a default constructor is Automatically generated and default values are used to initialize the Object Fields That is,…
-
8
votes4
answers3416
viewsHow to do a search to know if a string is inside a vector in C#
I’m doing a little program that searches inside a vector. The problem I’m having is that if he finds the name he gives a message saying it was found but then gives another message saying that it was…
-
8
votes2
answers1332
viewsConvert string to Datetime in LINQ
I have a model where all fields are string. I want to convert to DateTime and Double For that I created a new model public class CPUStats { public DateTime Data { get; set; } public Double? Disco {…
-
8
votes3
answers1793
viewsHow to divide integers and get value with decimal part?
I am trying to divide the following values into c#: Double media = 0.0; int soma = 7; int cont = 2; media = soma / cont; Is returning 3.…
-
8
votes4
answers8025
viewsCheck if int is "null" in C#
Cannot assign on C# null at an integer value (int, nay int?). However, how can I know if an integer value (int) has not yet had an assigned value (being of the type int)? int? valor; if (valor ==…
-
8
votes2
answers2113
viewsHow to create methods on an Enum?
I have an application in Java and am porting it to C#. I have a question regarding enum that seems to work differently from Java. After asking a question here on the site (Enumerations may contain…
-
8
votes3
answers370
viewsPrivate set of property in an interface
I’m modeling a C# interface that has a property. However, I want to ensure that all classes that implement this interface maintain the Setter as private: public interface IBar { string Id { get;…