interviews.dotnetthread.com

↑ Grab this Headline Animator

Friday, February 26, 2010

MS Excel like Ceiling function in c#.

- EXcel Ceiling function returns a number rounded up based on a multiple of significance.
- Example Ceiling(41.88, 10) will give 50 and Ceiling of 41.88 to 5 will give 45.
- Below is the C# function which gives the same result as Ceiling in MS Excel.



public int Ceiling(double input, int ceilTo)
{
if ((input % ceilTo) != 0)
{
return ((int)(input / ceilTo) * ceilTo) + ceilTo;
}
else
{
return Convert.ToInt32(input);
}
}

Submit this story to DotNetKicks

MS Excel like Round function in c#.

1. Excel Round function behaves differently when we compare with C# Math.Round() method.
2. Also Excel Round allows Round to -1, -2... example Round(121,-1) = 120. This is not allowed in Math.Round()
3. Say if we want to Round 1234.5678 to nearest integer value then Math.Round() returns 1234 where as MS Excel Round gives 12345.
4. Below is a C# function that gives similar result as MS Excel Round and also allows negative rounding.


public double roundNum(double num, int place)
{
double n;
n = num * Math.Pow(10, place);
n = Math.Sign(n) * Math.Abs(Math.Floor(n + .5));
return n / Math.Pow(10, place);
}



Note: Visual Studio 2005 allows us to mention Round Up or Round down for Math.Round() method.

Submit this story to DotNetKicks

Tuesday, November 3, 2009

Solution: How to change css class for an element in jquery?

In order to change the CSS class applied to an element using jQuery we can use methods like
addClass() and .removeClass()


$("#divId").addClass("classname");

$("#divId").removeClass("classname");


But if we want to change or toggle CSS class between two classes during some events like button click we can use method toggleClass() like below.

Say on click we need to change class from "btn_submit" and "btn_submit_active" or vise versa
if element has class "btn_submit_active" toggle to use "btn_submit". here we use toggleClass() method twise.


$("#divId").toggleClass("btn_submit");
$("#divId").toggleClass("btn_submit_active");

Submit this story to DotNetKicks

Wednesday, October 21, 2009

Visual Studio 2010 and .NET 4.0 Beta 2 Released

Visual Studio 2010 and .Net Framework 4.0 Beta 2 is released this wednesday.
This is available for download in MSDN here http://go.microsoft.com/fwlink/?LinkID=151797

Have a look at the style and view in the below image.



VS 2010 Features or Key Areas of improvements

- Advances for ASP.NET web development
- WPF and WinForms client development
- SharePoint development
- Silverlight development
- Data development
- Parallel computing development and
- cloud computing development.
- Lot of improvements in IDE and other tools
- Improvements in programming languages like C#

- Easy to install and use TFS for version management

We can have VS 2010 along with VS 2008 in our system.

Submit this story to DotNetKicks

Tuesday, October 20, 2009

JSON Serialization in VS 2008

Say we need to convert serialize C# object to JSON string and transfer that to client side to be used in Javascript. DataContract attribute is added to a class and DataMember attribute is added for all members that need be serialized.


[DataContract]
public class Employee
{
#region "Private Variables"
private string name = string.Empty;
private string id = string.Empty;
#endregion

#region "Public Properties"
[DataMember]
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
[DataMember]
public string ID
{
get
{
return this.id;
}

set
{
this.id = value;
}
}
}

Now in order to convert the above mentioned class object to JSON string use below code.

Employee obj = new Employee();
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
using (MemoryStream ms = new MemoryStream())
{
serializer.WriteObject(ms, obj);
ms.Flush();
byte[] bytes = ms.GetBuffer();
string jsonString = Encoding.UTF8.GetString(bytes, 0, bytes.Length).Trim('\0');
return jsonString;
}

Submit this story to DotNetKicks

Sunday, October 4, 2009

Junior Software Developer

Job Description

Position: Junior Software Developer
Apply Now
Requirements:

• Knowledge and experience in C# ,ASP.NET SQL and XML (academic project in NET is Must)
• Experience working in a variety of team sizes and excellent communication and interpersonal skills.

Desired Candidate Profile
We are looking to add a Junior Developer to our Engineering Team to assist in application development and daily operations. With a variety of coding languages and platforms, it is a challenging position that requires a desire to learn.

For More Details Click Here

Submit this story to DotNetKicks

 

Latest Articles