Questions tagged as 'c#'

3
answers

Run program within Try / Catch

Working with Visual Studio, when an error occurs while the program is running the program crashes and you can not see where the program crashed and only that error screen appeared. To get where these errors occur we use try catch , so w...
asked by 06.03.2014 / 13:24
2
answers

Can I use class and struct at the same time?

I have a "Address" variable, however, it is made up of "Street", "Number" and so on. The way I did below is the best one to do? With class and struct at the same time? Or is there something better and simpler to do? public struct...
asked by 28.09.2016 / 15:49
2
answers

How to declare a function inside another function in C #?

In Delphi it is possible to declare function within the block of a given function, see this example done in Delphi: procedure TForm1.btnRunClick(Sender: TObject); begin mostrarNome('Carvalho'); end; function TForm1.mostrarNome(nome: String)...
asked by 24.05.2016 / 03:20
2
answers

Collision of names between class and namespace

Is it wrong, bad practice or can I have problems with class equal to namespace ? Example: namespace Cielo { public class Cielo { } } It has worked, in some places it gets a bit strange to call Cielo.Cielo.etc . Should...
asked by 29.04.2016 / 20:08
2
answers

How to determine the last element of a list in a foreach?

Given any list, how do I know if foreach is in the last element? There are a few ways to do this, the most I can see is to save the last element and check if the current element is the same, but in that way it is necessary to check eve...
asked by 30.06.2016 / 16:07
3
answers

nullable on models?

What is the nullable in a model? For example: public int? ProjectId; If I put this way'm accepting null values, right? And if I put the annotation required on the property, is it required not to have the value be null or would it? Why...
asked by 11.09.2014 / 23:11
3
answers

How to intercept exceptions when working with the Entity Framework?

I want to handle the errors returned by the Entity Framework. In this example I'm forcing the insertion of a duplicate record (Name already in the database where the column of the table is configured as a Unique Index ): [HttpPost] [Validat...
asked by 13.06.2014 / 02:31
3
answers

LINQ corresponding to SQL with LIKE clause 'XXX%'

I'm using the following LINQ to return a query: .Where(c => c.Nome.Contains(nome)).OrderBy(c => c.Nome) But if the name is Maria , it brings: José Maria Maria José How to bring organized as if executing SQL query? So: WHE...
asked by 12.10.2015 / 21:38
4
answers

Make an update with lambda

I have a query in lambda that returns me a list of data. I would like to know how do I update this DB table using lambda? Let's say, I have a Table called T_PDV and in it a flag field, where milestone LIDO = 1 and if it is not LIDO = 0. This f...
asked by 02.06.2014 / 18:51
2
answers

Trigger event only once

I'm doing an interface in Visual Studio 2015, how do I perform an event only once? For example: private void textBox5_Click(object sender, EventArgs e) { textBox5.ForeColor = Color.Black; textBox5.SelectAll(); textBox5.Text =...
asked by 08.04.2016 / 19:31