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
-
2
votes1
answer74
viewsInstantiating a class "x" from another class "y" inherited by the class "x"
If I have a class Diretor who inherits from the class Funcionario, so I say a direct is also an employee. Public class Diretor : Funcionario{} Diretor diretor = new Diretor(); But I’m allowed to…
-
2
votes1
answer178
viewsIf in C# "Enum"s only accept whole types, why accept a "char"?
When we’re learning about enums in C# is said to accept only integer numeric types. Therefore, we soon think of sbyte, byte, short, ushort, int, uint, long or ulong. But the code below also works,…
-
2
votes0
answers30
viewsCan references affect performance?
In C#, for example, I can reference several namespaces: using System; using System.Collections.Generic; using System.Web.Security; using System.Web.UI; using System.Text; The very one Visual Studio,…
-
2
votes1
answer86
viewsInsert value in column C#
I have to read a column (which is the primary key of a table) and see if there is the value of a variable in that column, if it does not exist, I want to add it, if it exists, I want to move on. I…
-
2
votes1
answer345
viewsProblems when mapping Entity Framework database
I’m having trouble creating a solution to this business rule. I currently have 1 Customer, 1 Correspondent and 1 Store. Both use the same address table. Like the tables cliente, correspondente and…
-
2
votes1
answer6778
viewsThe INSERT statement conflicted with the FOREIGN KEY C#
I have this code to insert values into a table: conn.Open(); comm.CommandText = @"INSERT INTO ArticleBarCode(Code, Code_Article, BarCode, CreatedBy, CreatedOn, ModifiedBy, ModifiedOn, IsDeleted)…
-
2
votes1
answer38
viewsWhy in a generic-type method extension do I not need to spell out a type when calling it?
In the link below is a code snippet consisting of nothing more than a Shuffle method that is used as a Extension Method of Array. Although the method is generic type, I don’t need to pass a guy when…
-
2
votes1
answer61
viewsValidate Streamreader twice
I get a. csv file in my Controller. This file may contain two templates, with 2 or 5 lines. First I have to do the validation to check if the file contains 5 lines: var arquivo = new…
-
2
votes1
answer463
viewsError saving list of related objects
I’m using the BeginCollectionItem to insert objects related to a Cliente which I call Dependentes. When saving, I have the mistake: Violation of PRIMARY KEY constraint 'Pk_dbo.Dependents'. Not…
-
2
votes1
answer185
viewsThe 'Connection' object can be discarded more than once in the method
Follows the code: public ActionResult Index(ViewModel model, string returnUrl) { string query = "UPDATE Table SET Status = 'C' WHERE Id = @Num"; using (SqlConnection connection = new…
-
2
votes1
answer1000
viewsRecover image through path and display
I created the following method to save an image in the database public ActionResult enviaArquivo(UsurioViewModel arq) { try { string nomeArquivo =""; if (arq.Arquivo != null &&…
-
2
votes1
answer77
viewsError in Transactionscope
I’m trying to accomplish a TransactionScope but it always gives me a mistake: Server Error in Application '/'. A Second Operation Started on this context before a Previous asynchronous Operation…
-
2
votes1
answer167
viewsEdit object, with related objects
I Have an Object Cliente relating to two other objects. [Table("Cliente")] public class Cliente { [StringLength(100, ErrorMessage = "Este campor permite apenas 100 caracteres"), Required] public…
-
2
votes1
answer146
viewsReflection with list property
How to change the value of the class property in the list? My variable classPropValueList always comes void. I’m trying to make a Reflection of every class it inherits from Coisable, to change its…
-
2
votes1
answer112
viewsCreation of anonymous objects vs "named (?)"
I have a class that loga some information in the database I am using it in the following way: new StudyLogRepository().Create(new StudyLog() { StudyId = Study.Id, CycleId = null, DateOccurrence =…
c# asp.net-mvc .net entity-framework pattern-designasked 7 years, 5 months ago Jhonatan Jorge de Lima 1,012 -
2
votes1
answer40
viewsEF relationship from Foxpro migration, with composite key
I’m migrating a legacy Visualfox system on . Net where the tables were made all without relationship, in ADO, without Foreign key in relationships. Just comparing a string of the name "Type" to…
-
2
votes2
answers5321
viewsCalling an asynchronous and synchronous method
I have a synchronous method, in it I call another method of another controller which would have to be executed asynchronous. I call this other method this way: Task.Run(() =>…
-
2
votes1
answer33
viewsMultiple condition C#
I’m trying to validate if a user is a teacher and if they type "s" or "n" uppercase or lowercase but this getting caught in the loop with the condition being true or false. while ((array [i, 1] !=…
c#asked 3 years, 10 months ago Paulo César 23 -
2
votes1
answer139
viewsRegex to capture fixed strings in HTML and JS codes
I’m doing some automated testing for a project legacy in the MVC model, however, there is a requirement for one of them to capture all fixed strings in HTML and JS codes. Since the project company…
-
2
votes3
answers525
viewsHow to insert an existing record into the Entity Framework?
At some point in the system some records are selected and should be replicated by changing only one value. At this point I am selecting the records I need to enter: listaRegistros = listaRegistros…
-
2
votes2
answers464
viewsSave Objects Relationship Only - Entity Framework
Using the . Net platform with the Entity Framework. I am persisting an A_B class object that relates to A and B as code below: public class A_B { private int Id; private string name; private A a;…
-
2
votes0
answers123
viewsExcel Add-in Does Not Install
I have a Add-Inwho uses .Net Framework 4.0 and Visual Studio. It is working well with Office 2013. After the installation of Office 2016, when I try to install the same VSTO add-in is giving me a…
-
2
votes3
answers92
viewsVB.NET to C#
I found this line of code: Try Dim WebReq As HttpWebRequest = HttpWebRequest.Create(GET_Data) Using WebRes As HttpWebResponse = WebReq.GetResponse Using Reader As New…
-
2
votes2
answers437
viewsPutting social media buttons on the site
I am "playing" with the SPA MVC(C#) and would like to know how I put the social media buttons on my site. I looked for some examples here on the site and by my query, I found nothing that satisfied…
-
2
votes1
answer756
views -
2
votes2
answers434
viewsInput Submit does not call Actionresult
I’m having trouble calling Actionresult using input type="submit" and pass the model data. I did a test using ActionLink but Model is not sent. Someone could shed a light? Here is the code:…
-
2
votes1
answer30
viewsAfter passing a class by interface reference, how to recover your Type?
If I receive a class by interface reference, is there any way to recover the original type that implemented it? This way I could spend it on an overload of methods for each specific type. Or this is…
-
2
votes1
answer478
viewsStatic properties and memory release
I’m having some doubts regarding the release of resources for cases where my modifiers are static. My project is unit test and I’m using Selenium for the first time. public class LoginTest : Base {…
-
2
votes1
answer285
viewsC# How to rename MANY files faster or at the same time?
So guys, I’m creating here a program to rename files, the code I’ve made is very slow and only renames one file at a time, and I can’t create a code to rename all at once because they’re different…
-
2
votes1
answer116
viewsBuild error due to lack of constructor
I have the following classes: class Disciplina: public class Disciplina { public int Id { get; set; } public string Nome { get; set; } } interface IGenericaDAO: public interface…
-
2
votes1
answer53928
viewsHow to resolve Object Reference Not Set To An Instance Of An Object
I have a serious problem. I have a Gridview populated with data from a Mysql BD working perfectly. I also have a button to turn it into a table to be inserted into a PDF using iTextSharp that also…
-
2
votes3
answers70
viewsBecause I would do Downcasting and Upcasting on C#
To be more specific, I understood the concepts and everything, but I don’t have a real-life example that I would need to do upcasting or downcasting, for example Businessaccount inherits from…
c#asked 3 years, 7 months ago Brener Sousa 35 -
2
votes1
answer41
viewsRegex in Javascript and C# for text validation
In an application Asp.Net WebForms, have a TextBox which I need to validate if it contains any excerpts where there are < followed by any character except blank space. For example: Nesse texto…
-
2
votes2
answers55
viewsWhat is the Bufferedstream of C#?
I need to accumulate bytes in a buffer and then download them into a file. I used a few tricks for it but I was told there’s a little guy who can help me, BufferedStream. By instantiating it, I set…
-
2
votes1
answer744
viewsPrintscreen in C#
I want to make a program that takes printscreen of a window defined by me in C# So far I’ve made that code: private void btPrintScreenEcra_Click(object sender, EventArgs e) { //Definimos qual a…
c#asked 7 years, 4 months ago Frederico Sampaio 57 -
2
votes1
answer112
viewsDoubt with List C#
After consulting the data, keeping them in memory and using "Contains" to locate a product, what would be the best way to do this? thanks I have my DAL: public class BuscaProdutosDermaDAL { private…
-
2
votes3
answers725
viewsASP.NET MVC Web - How to separate performance between the modules of a project?
Explaining the doubt. Within my system there are some menus, we will use as example 3, naming them A, B and C, each being a CRUD module with some kind of report. If 300 people are using module A, it…
-
2
votes2
answers239
viewsChanging Cell Color according to IF condition in C# WPF source code
I have a Datagrid in a form in C# WPF, as it is possible to execute a method recovers each Cell contained in that Datagrid and assign a possible value, or change the background color? For example I…
-
2
votes2
answers46
viewsEnum initialization
I’ve always created enums thus: public enum TipoTelefone { Residencial, Celular, Comercial } But today giving maintenance on a code I found one like this: public enum TipoTelefone { Residencial = 0,…
-
2
votes2
answers121
viewsHow to screen a serialized object?
I’m trying to convert an object that contains a relationship and Serializando afim, to send it to View by Ajax. I have two related classes public class Eventos : IEntidade<EventosAuditoria> {…
-
2
votes1
answer1305
viewsGenerate more than one PDF in memory and export it in a compressed file
Currently the code below exports and compresses the PDF one at a time and need to export multiple PDF in one compressed file public ActionResult PDFTodosMesAtual(ProcessamentoRegistros…
-
2
votes1
answer227
viewsLogin with facebook in Xamarin Forms with Azure Mobile Apps
I’m building an app (with Xamarin.Forms Pcl), where I have a login with facebook, using the Azure Mobile Client SDK. It is possible to perform the authentication, however, right after the…
-
2
votes2
answers567
viewsCompare current date with saved in database and return validation
I’m developing a program where there’s a 15-day trial period. When the user registers an account in the application, it takes the internet date and registers the current date and the date of the end…
c#asked 7 years, 4 months ago Marlon Pereira 465 -
2
votes1
answer431
viewsAnimate a side menu in WPF
Hello, I’m now entering the world WPF (I come from MVC), and I’m with a question: I’m trying to animate an expandable menu, IE, when the user clicks the button, it expands and when you click again…
-
2
votes2
answers1339
viewsOpen PDF in browser automatically after download
The downalod from the PDF is executed correctly (is minimized at the bottom corner of the browser). How to make it open automatically in a new guide ?: <a href="#" class="download"…
-
2
votes1
answer1635
viewsReturn Controller List to View
I have a controller where the information of the ModelState, store errors in a list. I would like to take this list and return to my view. But I’m a beginner and I’m not getting to understand how I…
-
2
votes1
answer309
viewsEntity Framework - Error?
I’m following a tutorial from Entity framework: Simple Code First Example it is quite simple, but for some reason it is not working here and appears the error message is as follows: Aspnet Projects…
-
2
votes1
answer2388
viewsHow to download file via $.ajax()
This doubt arose from this post Send data to an Actionresult from a Controller other than the current one answered by Tiago S, currently have this ActionResult that downloads file through a Post in…
-
2
votes2
answers104
viewsRemove user without deleting from database
I need help from you, I created two classes within my Controller, where I can remove a user from one page and send to another. As if deleting but not erasing from the database. I created a variable…
-
2
votes1
answer62
viewsParse data from a C#database?
Precise deserialize the information of a database in C#, I have the following SQL in C#: select Id, Email, Name, Login FROM usuarios WHERE Login = @login and Senha = CONVERT(VARCHAR(2000),…